vite.config.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. resolve: {
  8. alias: {
  9. '~src': `${resolve(__dirname, './src')}`,
  10. '~ass': resolve(__dirname, './src/assets'),
  11. '~com': `${resolve(__dirname, './src/components')}`,
  12. '~api': resolve(__dirname, './src/api/modules'),
  13. '~sto': resolve(__dirname, './src/store/modules'),
  14. '~uti': resolve(__dirname, './src/utils')
  15. }
  16. },
  17. plugins: [
  18. vue(),
  19. ],
  20. build: {
  21. rollupOptions: {
  22. output: {
  23. manualChunks(id) {
  24. let libStr = '@vue,tailwindcss,element-plus,echarts,vue-router,pinia,js-fast-way,vue3-tree-org';
  25. const libs = libStr.split(',')
  26. if (id.includes('node_modules')) {
  27. const arr = id.toString().split('node_modules/')[1].split('/')
  28. if (libs.indexOf(arr[0]) !== -1) {
  29. return '_' + arr[0]
  30. } else {
  31. return '__vendor'
  32. }
  33. }
  34. },
  35. chunkFileNames: 'static/js1/[name]-[hash].js',
  36. entryFileNames: 'static/js2/[name]-[hash].js',
  37. assetFileNames: 'static/[ext]/[name]-[hash].[ext]'
  38. },
  39. brotliSize: false, // 不统计
  40. target: 'esnext',
  41. minify: 'esbuild' // 混淆器,terser构建后文件体积更小
  42. }
  43. },
  44. server: {
  45. ...config.vite,
  46. proxy: {
  47. '/api': {
  48. ws: true,
  49. changeOrigin: true,
  50. target: config.target,
  51. rewrite: (path) => path.replace(new RegExp('^/api'), '/'),
  52. }
  53. }
  54. },
  55. })