From ba2aff52ef1f1bce602c01dfc873af110461c24c Mon Sep 17 00:00:00 2001 From: a12110 Date: Sun, 12 Apr 2026 16:13:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0:=20=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E4=B8=BA=E9=9D=9EElectron=E7=8E=AF=E5=A2=83=E4=B8=8B=20?= =?UTF-8?q?=E6=89=8D=E5=8A=A0=E8=BD=BD=20.env=20=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E4=B8=AD=E7=9A=84=E7=8E=AF=E5=A2=83=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/env.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/env.ts b/src/env.ts index ca3c960..09af65c 100644 --- a/src/env.ts +++ b/src/env.ts @@ -1,11 +1,6 @@ import dotenv from "dotenv"; import path from "node:path"; -dotenv.config({ - path: path.resolve(process.cwd(), ".env"), -}); - - // 判断是否为打包后的 Electron 环境 const isElectron = typeof process.versions?.electron !== "undefined"; let isPackaged = false; @@ -14,6 +9,13 @@ if (isElectron) { isPackaged = app.isPackaged; } +// 仅在非 Electron 环境加载 .env(例如 Docker / Web 后端) +if (!isElectron) { + dotenv.config({ + path: path.resolve(process.cwd(), ".env"), + }); +} + //加载环境变量(打包环境默认使用 prod) const env = process.env.NODE_ENV; if (!env) {