vite.config.ts 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import { UserConfig, ConfigEnv } from 'vite';
  2. import { resolve } from 'path';
  3. import { createVitePlugins } from './vite/plugin';
  4. import { generateModifyVars } from './vite/themeConfig';
  5. import { proxy } from './vite/proxy';
  6. const root = process.cwd();
  7. // https://vitejs.dev/config/
  8. export default ({ command, mode }: ConfigEnv): UserConfig => {
  9. console.log('vite >>>', command, mode);
  10. const isBuild = command === 'build';
  11. return {
  12. root,
  13. resolve: {
  14. alias: [
  15. {
  16. find: /^@\//,
  17. replacement: resolve(root, './src') + '/'
  18. }
  19. ]
  20. },
  21. css: {
  22. preprocessorOptions: {
  23. less: {
  24. // 解决antd less loader版本高的问题
  25. javascriptEnabled: true,
  26. modifyVars: generateModifyVars()
  27. }
  28. }
  29. },
  30. build: {
  31. target: 'es2015',
  32. terserOptions: {
  33. compress: {
  34. // TODO:
  35. keep_infinity: true,
  36. // 自动删除console
  37. drop_console: true,
  38. // 自动删除debugger
  39. drop_debugger: true
  40. }
  41. },
  42. // bortli压缩大小报告,压缩大型输出文件可能会慢,禁用提高大型项目的构建性能
  43. brotliSize: false,
  44. // 块大小警告的限制(单位 kbs),默认500
  45. chunkSizeWarningLimit: 2000
  46. },
  47. plugins: createVitePlugins(isBuild, mode),
  48. server: {
  49. hmr: {
  50. // 禁用服务器错误的遮罩层
  51. overlay: false
  52. },
  53. open: true,
  54. proxy
  55. }
  56. };
  57. };