diff --git a/.gitignore b/.gitignore index a4b2189..a876d5c 100644 --- a/.gitignore +++ b/.gitignore @@ -23,15 +23,11 @@ package-lock.json .VSCodeCounter **/backend-mock/data -# local env files -.env -.env.* -apps/*/.env -apps/*/.env.* -!.env.example -!apps/*/.env.example +# local env override files .env.local .env.*.local +apps/*/.env.local +apps/*/.env.*.local .eslintcache logs diff --git a/apps/web-antdv-next/.env b/apps/web-antdv-next/.env new file mode 100644 index 0000000..6873f92 --- /dev/null +++ b/apps/web-antdv-next/.env @@ -0,0 +1,8 @@ +# 应用标题 +VITE_APP_TITLE=Vben Admin Antdv Next + +# 应用命名空间,用于缓存、store等功能的前缀,确保隔离 +VITE_APP_NAMESPACE=vben-web-antdv-next + +# 对store进行加密的密钥,在将store持久化到localStorage时会使用该密钥进行加密 +VITE_APP_STORE_SECURE_KEY=kwitsukasa diff --git a/apps/web-antdv-next/.env.analyze b/apps/web-antdv-next/.env.analyze new file mode 100644 index 0000000..ffafa8d --- /dev/null +++ b/apps/web-antdv-next/.env.analyze @@ -0,0 +1,7 @@ +# public path +VITE_BASE=/ + +# Basic interface address SPA +VITE_GLOB_API_URL=/api + +VITE_VISUALIZER=true diff --git a/apps/web-antdv-next/.env.development b/apps/web-antdv-next/.env.development new file mode 100644 index 0000000..3b8df81 --- /dev/null +++ b/apps/web-antdv-next/.env.development @@ -0,0 +1,17 @@ +# 端口号 +VITE_PORT=5999 + +VITE_BASE=/ +VITE_ROUTER_HISTORY=hash + +# 接口地址 +VITE_GLOB_API_URL=/api + +# 是否开启 Nitro Mock服务,true 为开启,false 为关闭 +VITE_NITRO_MOCK=false + +# 是否打开 devtools,true 为打开,false 为关闭 +VITE_DEVTOOLS=false + +# 是否注入全局loading +VITE_INJECT_APP_LOADING=true diff --git a/apps/web-antdv-next/.env.production b/apps/web-antdv-next/.env.production new file mode 100644 index 0000000..c1a6a11 --- /dev/null +++ b/apps/web-antdv-next/.env.production @@ -0,0 +1,19 @@ +VITE_BASE=/ + +# 接口地址 +VITE_GLOB_API_URL=/api + +# 是否开启压缩,可以设置为 none, brotli, gzip +VITE_COMPRESS=none + +# 是否开启 PWA +VITE_PWA=false + +# vue-router 的模式 +VITE_ROUTER_HISTORY=hash + +# 是否注入全局loading +VITE_INJECT_APP_LOADING=true + +# 打包后是否生成dist.zip +VITE_ARCHIVER=true diff --git a/internal/vite-config/src/utils/env.ts b/internal/vite-config/src/utils/env.ts index f342216..8862aa1 100644 --- a/internal/vite-config/src/utils/env.ts +++ b/internal/vite-config/src/utils/env.ts @@ -39,6 +39,7 @@ async function loadEnv>( confFiles = getConfFiles(), ) { let envConfig = {}; + const reg = new RegExp(`^(${match})`); for (const confFile of confFiles) { try { @@ -54,7 +55,13 @@ async function loadEnv>( console.error(`Error while parsing ${confFile}`, error); } } - const reg = new RegExp(`^(${match})`); + + for (const [key, value] of Object.entries(process.env)) { + if (reg.test(key) && value !== undefined) { + envConfig = { ...envConfig, [key]: value }; + } + } + Object.keys(envConfig).forEach((key) => { if (!reg.test(key)) { Reflect.deleteProperty(envConfig, key);