vite.config.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import { defineConfig } from 'vite'
  2. import vue from '@vitejs/plugin-vue'
  3. import { resolve } from 'path'
  4. import config from './src/config'
  5. // https://vitejs.dev/config/
  6. export default defineConfig({
  7. css: {
  8. extract: true,
  9. preprocessorOptions: {
  10. scss: {
  11. additionalData: '@import "./src/styles/app/_var.scss";',
  12. },
  13. },
  14. },
  15. resolve: {
  16. alias: {
  17. '~src': `${resolve(__dirname, './src')}`,
  18. '~ass': resolve(__dirname, './src/assets'),
  19. '~com': `${resolve(__dirname, './src/components')}`,
  20. '~api': resolve(__dirname, './src/api/modules'),
  21. '~sto': resolve(__dirname, './src/store/modules'),
  22. '~uti': resolve(__dirname, './src/utils'),
  23. },
  24. },
  25. plugins: [
  26. vue(),
  27. ],
  28. build: {
  29. rollupOptions: {
  30. output: {
  31. manualChunks(id) {
  32. let libStr = '@vue,tailwindcss,element-plus,z-element-plus,echarts,vue-router,pinia,js-fast-way'
  33. const libs = libStr.split(',')
  34. if (id.includes('node_modules')) {
  35. const arr = id.toString().split('node_modules/')[1].split('/')
  36. if (libs.indexOf(arr[0]) !== -1) {
  37. return '_' + arr[0]
  38. } else {
  39. return '__vendor'
  40. }
  41. }
  42. },
  43. chunkFileNames: 'static/js1/[name]-[hash].js',
  44. entryFileNames: 'static/js2/[name]-[hash].js',
  45. assetFileNames: 'static/[ext]/[name]-[hash].[ext]',
  46. },
  47. brotliSize: false, // 不统计
  48. target: 'esnext',
  49. minify: 'esbuild', // 混淆器,terser构建后文件体积更小
  50. },
  51. },
  52. server: {
  53. ...config.vite,
  54. proxy: {
  55. '/api': {
  56. ws: true,
  57. changeOrigin: true,
  58. target: config.target,
  59. rewrite: (path) => path.replace(new RegExp('^/api'), '/'),
  60. },
  61. },
  62. },
  63. })