vite.config.js 2.4 KB

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