vite.config.ts 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. import { fileURLToPath, URL } from 'node:url'
  2. import { defineConfig, loadEnv } from 'vite'
  3. import { createVitePlugins } from './vitePlugins.config'
  4. import { createProxy } from './viteProxy.config'
  5. import type { ImportMetaEnv } from './env'
  6. // https://vite.dev/config/
  7. export default defineConfig(({ mode }) => {
  8. const rawEnv = loadEnv(mode, process.cwd())
  9. console.log({ mode, rawEnv })
  10. const env: ImportMetaEnv = {
  11. VITE_GLOB_APP_TITLE: rawEnv.VITE_GLOB_APP_TITLE || 'FranklinWH Toolbox',
  12. VITE_GLOB_APP_NAME: rawEnv.VITE_GLOB_APP_NAME || 'FWH Toolbox',
  13. VITE_USER_NODE_ENV: rawEnv.VITE_USER_NODE_ENV || 'development',
  14. VITE_PUBLIC_PATH: rawEnv.VITE_PUBLIC_PATH || '/',
  15. VITE_ROUTER_MODE: rawEnv.VITE_ROUTER_MODE || 'hash',
  16. VITE_API_URL: rawEnv.VITE_API_URL || '/fwh-toolbox/api',
  17. // 仅development环境生效
  18. VITE_PORT: rawEnv.VITE_PORT,
  19. VITE_OPEN: rawEnv.VITE_OPEN,
  20. VITE_DEVTOOLS: rawEnv.VITE_DEVTOOLS,
  21. VITE_CODEINSPECTOR: rawEnv.VITE_CODEINSPECTOR,
  22. // 仅production打包
  23. VITE_REPORT: rawEnv.VITE_REPORT,
  24. VITE_DROP_CONSOLE: rawEnv.VITE_DROP_CONSOLE,
  25. VITE_BUILD_COMPRESS: rawEnv.VITE_BUILD_COMPRESS,
  26. VITE_BUILD_COMPRESS_DELETE_ORIGIN_FILE: rawEnv.VITE_BUILD_COMPRESS_DELETE_ORIGIN_FILE,
  27. }
  28. return {
  29. base: env.VITE_PUBLIC_PATH,
  30. plugins: createVitePlugins(env),
  31. resolve: {
  32. alias: {
  33. '@': fileURLToPath(new URL('./src', import.meta.url)),
  34. },
  35. },
  36. server: {
  37. host: '0.0.0.0',
  38. port: env.VITE_PORT ? Number(env.VITE_PORT) : undefined,
  39. open: env.VITE_OPEN === 'true',
  40. cors: true,
  41. // Load proxy configuration from .env.development
  42. proxy: createProxy(env.VITE_PUBLIC_PATH, true),
  43. allowedHosts: true,
  44. },
  45. build: {
  46. sourcemap: true, // ✅ 生成 source map
  47. // rolldownOptions: {
  48. // output: {
  49. // advancedChunks: {
  50. // includeDependenciesRecursively: true,
  51. // minSize: 50 * 1024, // 全局最小 50KB
  52. // maxSize: 300 * 1024, // 全局最大 300KB
  53. // minShareCount: 1,
  54. // groups: [
  55. // {
  56. // name: 'vue',
  57. // test: /node_modules[\\/]vue/,
  58. // priority: 10,
  59. // },
  60. // {
  61. // name: 'g2',
  62. // test: /node_modules[\\/]@antv[\\/]g2/,
  63. // priority: 9,
  64. // },
  65. // {
  66. // name: 'g-webgl',
  67. // test: /node_modules[\\/]@antv[\\/]g-webgl/,
  68. // priority: 9,
  69. // },
  70. // {
  71. // name: 'naive-ui',
  72. // test: /node_modules[\\/]naive-ui/,
  73. // priority: 8,
  74. // },
  75. // {
  76. // name: 'icons',
  77. // test: /node_modules[\\/]@iconify-json[\\/]/,
  78. // priority: 7,
  79. // },
  80. // {
  81. // name: 'utils',
  82. // test: /node_modules[\\/](dayjs|chroma-js|uuid|@vueuse)/,
  83. // priority: 6,
  84. // },
  85. // {
  86. // name: (id) =>
  87. // id.includes('src/components/fullScreenCanvas') ? 'fullScreenCanvas' : null,
  88. // test: (id) => id.includes('src/components/fullScreenCanvas'),
  89. // priority: 5,
  90. // },
  91. // {
  92. // name: 'vendor', // fallback
  93. // test: /node_modules/,
  94. // priority: 1,
  95. // },
  96. // ],
  97. // },
  98. // },
  99. // },
  100. },
  101. }
  102. })