diff --git a/.env.product b/.env.production similarity index 100% rename from .env.product rename to .env.production diff --git a/package.json b/package.json index 92f36d6..b4b7954 100644 --- a/package.json +++ b/package.json @@ -8,11 +8,11 @@ }, "scripts": { "dev": "vite", - "dev:prod": "vite --mode product", + "dev:prod": "vite --mode production", "build:test": "vite build --mode development", "preview:test": "vite preview --mode development", - "build:prod": "vite build --mode product", - "preview:prod": "vite preview --mode product", + "build:prod": "vite build --mode production", + "preview:prod": "vite preview --mode production", "build:all": "npm run build:test && npm run build:prod" }, "dependencies": { diff --git a/vite.config.js b/vite.config.js index 22226c6..1de2492 100644 --- a/vite.config.js +++ b/vite.config.js @@ -5,12 +5,12 @@ import vueDevTools from 'vite-plugin-vue-devtools' // https://vite.dev/config/ export default defineConfig(({ mode, command }) => { - // 加载环境变量 - const env = loadEnv(mode, process.cwd(), '') + // 正确加载环境变量 - 只加载 VITE_ 前缀的变量:cite[9] + const env = loadEnv(mode, process.cwd(), 'VITE_') const outDirMap = { development: 'dist-test', - product: 'dist-prod' + production: 'dist-prod' } return { @@ -45,10 +45,5 @@ export default defineConfig(({ mode, command }) => { port: 5173, open: true }, - // 确保环境变量在构建时被正确处理 - define: { - 'import.meta.env.VITE_API_BASE_URL': JSON.stringify(env.VITE_API_BASE_URL), - 'import.meta.env.VITE_APP_ENV': JSON.stringify(env.VITE_APP_ENV) - } } }) \ No newline at end of file