vite.config.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. javascriptEnabled: true,
  25. modifyVars: generateModifyVars()
  26. }
  27. }
  28. },
  29. build: {
  30. target: 'es2015',
  31. terserOptions: {
  32. compress: {
  33. // TODO:
  34. keep_infinity: true,
  35. drop_console: true,
  36. drop_debugger: true
  37. }
  38. },
  39. // TODO:
  40. brotliSize: false,
  41. // TODO:
  42. chunkSizeWarningLimit: 2000
  43. },
  44. plugins: createVitePlugins(isBuild, mode),
  45. server: {
  46. hmr: {
  47. // 禁用服务器错误的遮罩层
  48. overlay: false
  49. },
  50. open: true,
  51. proxy
  52. }
  53. };
  54. };