build.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /**
  2. * Copyright (c) 2013-Now https://jeesite.com All rights reserved.
  3. * No deletion without permission, or be held responsible to law.
  4. * @author ThinkGem
  5. */
  6. import type { BuildOptions } from 'vite';
  7. // 现代浏览器支持列表 https://cn.vitejs.dev/config/build-options.html#build-target
  8. export const viteTarget = ['chrome107', 'edge107', 'firefox104', 'safari16'];
  9. // 低版本浏览器支持列表,VITE_LEGACY 参数开启时有效 https://www.npmjs.com/package/@vitejs/plugin-legacy
  10. export const legacyTargets = ['chrome>=87', 'edge>=88', 'firefox>=78', 'safari>=14'];
  11. export function createBuildOptions(viteEnv: ViteEnv): BuildOptions {
  12. const timestamp = new Date().getTime();
  13. return {
  14. target: viteTarget,
  15. cssTarget: viteTarget,
  16. outDir: viteEnv.VITE_OUTPUT_DIR ?? 'dist',
  17. // 启用 terser 缩小器,当设置 terserOptions 时才会有效
  18. // minify: 'terser',
  19. // terserOptions: {
  20. // compress: {
  21. // keep_infinity: true,
  22. // drop_console: viteEnv.VITE_DROP_CONSOLE,
  23. // },
  24. // },
  25. // 禁用报告压缩块大小,可以稍微提高构建速度
  26. reportCompressedSize: false,
  27. chunkSizeWarningLimit: 9000,
  28. rollupOptions: {
  29. maxParallelFileOps: 50,
  30. output: {
  31. entryFileNames: `assets/[name]-[hash]-${timestamp}.js`,
  32. experimentalMinChunkSize: 12288,
  33. // manualChunks: {
  34. // vue: ['vue', 'vue-router'],
  35. // antd: ['ant-design-vue', '@ant-design/icons-vue'],
  36. // },
  37. },
  38. },
  39. };
  40. }