vite.config.js 2.0 KB

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