更新: 修改为非Electron环境下 才加载 .env 文件中的环境配置
This commit is contained in:
parent
b74aba8097
commit
ba2aff52ef
12
src/env.ts
12
src/env.ts
@ -1,11 +1,6 @@
|
|||||||
import dotenv from "dotenv";
|
import dotenv from "dotenv";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
|
|
||||||
dotenv.config({
|
|
||||||
path: path.resolve(process.cwd(), ".env"),
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
// 判断是否为打包后的 Electron 环境
|
// 判断是否为打包后的 Electron 环境
|
||||||
const isElectron = typeof process.versions?.electron !== "undefined";
|
const isElectron = typeof process.versions?.electron !== "undefined";
|
||||||
let isPackaged = false;
|
let isPackaged = false;
|
||||||
@ -14,6 +9,13 @@ if (isElectron) {
|
|||||||
isPackaged = app.isPackaged;
|
isPackaged = app.isPackaged;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 仅在非 Electron 环境加载 .env(例如 Docker / Web 后端)
|
||||||
|
if (!isElectron) {
|
||||||
|
dotenv.config({
|
||||||
|
path: path.resolve(process.cwd(), ".env"),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
//加载环境变量(打包环境默认使用 prod)
|
//加载环境变量(打包环境默认使用 prod)
|
||||||
const env = process.env.NODE_ENV;
|
const env = process.env.NODE_ENV;
|
||||||
if (!env) {
|
if (!env) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user