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.
 
 
 
 
 
 

34 lines
926 B

import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
// 使用函数式配置接收环境模式参数
export default defineConfig(({ mode }) => ({
plugins: [
vue({
template: {
compilerOptions: {
// 保留自定义元素配置
isCustomElement: tag => tag.startsWith('a-')
}
}
}),
],
define: {
// 注入当前构建模式到应用环境
__APP_ENV__: JSON.stringify(mode),
// 可选:保留原有 process.env 的浏览器环境兼容
'process.env.NODE_ENV': JSON.stringify(mode)
},
// 其他推荐生产环境配置(根据模式自动生效)
build: {
sourcemap: mode === 'development', // 开发模式开启sourcemap
minify: mode === 'production' ? 'terser' : false,
terserOptions: {
compress: {
drop_console: mode === 'production' // 生产环境移除console
}
}
}
}));