You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.1 KiB
43 lines
1.1 KiB
import { defineConfig, loadEnv } from 'vite'
|
|
import vue from '@vitejs/plugin-vue'
|
|
import { fileURLToPath, URL } from 'node:url'
|
|
|
|
export default defineConfig(({ mode }) => {
|
|
// 加载环境变量
|
|
const env = loadEnv(mode, process.cwd(), '')
|
|
|
|
return {
|
|
plugins: [vue()],
|
|
resolve: {
|
|
alias: {
|
|
'@': fileURLToPath(new URL('./src', import.meta.url))
|
|
}
|
|
},
|
|
server: {
|
|
port: 3000,
|
|
open: true
|
|
},
|
|
// 定义全局常量替换
|
|
define: {
|
|
// 确保环境变量在构建时被正确替换
|
|
__APP_ENV__: JSON.stringify(env.VITE_APP_ENV || mode)
|
|
},
|
|
// 构建配置
|
|
build: {
|
|
// 从环境变量读取构建输出目录,如果没有则使用默认值
|
|
outDir: env.VITE_BUILD_OUT_DIR || 'dist',
|
|
sourcemap: mode === 'development',
|
|
// 根据环境输出不同的构建产物名称
|
|
rollupOptions: {
|
|
output: {
|
|
// 可以根据环境自定义输出文件名
|
|
entryFileNames: `assets/[name].${mode}.js`,
|
|
chunkFileNames: `assets/[name].${mode}.js`,
|
|
assetFileNames: `assets/[name].${mode}.[ext]`
|
|
}
|
|
}
|
|
}
|
|
}
|
|
})
|
|
|