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.

33 lines
926 B

1 month ago
  1. import { defineConfig } from "vite";
  2. import vue from "@vitejs/plugin-vue";
  3. // 使用函数式配置接收环境模式参数
  4. export default defineConfig(({ mode }) => ({
  5. plugins: [
  6. vue({
  7. template: {
  8. compilerOptions: {
  9. // 保留自定义元素配置
  10. isCustomElement: tag => tag.startsWith('a-')
  11. }
  12. }
  13. }),
  14. ],
  15. define: {
  16. // 注入当前构建模式到应用环境
  17. __APP_ENV__: JSON.stringify(mode),
  18. // 可选:保留原有 process.env 的浏览器环境兼容
  19. 'process.env.NODE_ENV': JSON.stringify(mode)
  20. },
  21. // 其他推荐生产环境配置(根据模式自动生效)
  22. build: {
  23. sourcemap: mode === 'development', // 开发模式开启sourcemap
  24. minify: mode === 'production' ? 'terser' : false,
  25. terserOptions: {
  26. compress: {
  27. drop_console: mode === 'production' // 生产环境移除console
  28. }
  29. }
  30. }
  31. }));