vite.config.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. import { defineConfig, loadEnv } from 'vite'
  2. import vue from '@vitejs/plugin-vue'
  3. import { resolve } from 'path'
  4. import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
  5. import { mockDevServerPlugin } from 'vite-plugin-mock-dev-server'
  6. import envConfig from './env.config.js'
  7. export default defineConfig(({ mode }) => {
  8. const env = loadEnv(mode, process.cwd(), '')
  9. const currentEnv = envConfig[mode] || envConfig.development
  10. return {
  11. plugins: [
  12. vue(),
  13. createSvgIconsPlugin({
  14. iconDirs: [resolve(process.cwd(), 'src/icons')],
  15. symbolId: 'icon-[dir]-[name]',
  16. }),
  17. mockDevServerPlugin({
  18. logLevel: 'info',
  19. }),
  20. ],
  21. resolve: {
  22. alias: {
  23. '@': resolve(__dirname, 'src'),
  24. },
  25. extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue'],
  26. },
  27. assetsInclude: ['**/*.png', '**/*.jpg', '**/*.jpeg', '**/*.gif', '**/*.svg'],
  28. css: {
  29. preprocessorOptions: {
  30. scss: {
  31. additionalData: `
  32. $main-bg-color: #f5f5f5;
  33. $base-color: #409EFF;
  34. $nav-height: 80px;
  35. $side-close-width: 65px;
  36. $side-open-width: 160px;
  37. $sideBgColor: #121213;
  38. $sideTextColor: #fff;
  39. $sideActiveTextColor: #ffd04b;
  40. `,
  41. },
  42. },
  43. },
  44. server: {
  45. host: '0.0.0.0',
  46. port: 3000,
  47. open: false,
  48. proxy: {
  49. '/ws': {
  50. target: 'https://apis.map.qq.com',
  51. changeOrigin: true,
  52. ws: false,
  53. }
  54. }
  55. },
  56. build: {
  57. target: 'es2020',
  58. outDir: 'dist',
  59. assetsDir: 'assets',
  60. sourcemap: false,
  61. minify: 'terser',
  62. rollupOptions: {
  63. output: {
  64. chunkFileNames: 'js/[name]-[hash].js',
  65. entryFileNames: 'js/[name]-[hash].js',
  66. assetFileNames: '[ext]/[name]-[hash].[ext]',
  67. manualChunks: {
  68. vue: ['vue', 'vue-router', 'vuex'],
  69. elementPlus: ['element-plus'],
  70. echarts: ['echarts'],
  71. },
  72. },
  73. },
  74. terserOptions: {
  75. compress: {
  76. drop_console: false,
  77. drop_debugger: true,
  78. },
  79. },
  80. },
  81. define: {
  82. VE_ENV: {
  83. MODE: currentEnv.NODE_ENV,
  84. SERVER: currentEnv.SERVER,
  85. PYSERVER: currentEnv.PYSERVER,
  86. MOCK: currentEnv.MOCK
  87. },
  88. },
  89. optimizeDeps: {
  90. include: [
  91. 'vue',
  92. 'vue-router',
  93. 'vuex',
  94. 'element-plus',
  95. 'axios',
  96. 'echarts',
  97. 'dayjs',
  98. 'xe-utils',
  99. ],
  100. },
  101. esbuild: {
  102. loader: 'jsx',
  103. include: /src\/.*\.js$/,
  104. exclude: [],
  105. },
  106. }
  107. })