fix: 恢复前端环境配置并修复运行时注入

This commit is contained in:
sunlei 2026-06-02 09:17:55 +08:00
parent 506456b01b
commit 7638250c70
6 changed files with 62 additions and 8 deletions

10
.gitignore vendored
View File

@ -23,15 +23,11 @@ package-lock.json
.VSCodeCounter .VSCodeCounter
**/backend-mock/data **/backend-mock/data
# local env files # local env override files
.env
.env.*
apps/*/.env
apps/*/.env.*
!.env.example
!apps/*/.env.example
.env.local .env.local
.env.*.local .env.*.local
apps/*/.env.local
apps/*/.env.*.local
.eslintcache .eslintcache
logs logs

8
apps/web-antdv-next/.env Normal file
View File

@ -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

View File

@ -0,0 +1,7 @@
# public path
VITE_BASE=/
# Basic interface address SPA
VITE_GLOB_API_URL=/api
VITE_VISUALIZER=true

View File

@ -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
# 是否打开 devtoolstrue 为打开false 为关闭
VITE_DEVTOOLS=false
# 是否注入全局loading
VITE_INJECT_APP_LOADING=true

View File

@ -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

View File

@ -39,6 +39,7 @@ async function loadEnv<T = Record<string, string>>(
confFiles = getConfFiles(), confFiles = getConfFiles(),
) { ) {
let envConfig = {}; let envConfig = {};
const reg = new RegExp(`^(${match})`);
for (const confFile of confFiles) { for (const confFile of confFiles) {
try { try {
@ -54,7 +55,13 @@ async function loadEnv<T = Record<string, string>>(
console.error(`Error while parsing ${confFile}`, error); 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) => { Object.keys(envConfig).forEach((key) => {
if (!reg.test(key)) { if (!reg.test(key)) {
Reflect.deleteProperty(envConfig, key); Reflect.deleteProperty(envConfig, key);