vite.config.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. css: {
  9. extract: true,
  10. },
  11. resolve: {
  12. alias: {
  13. '~src': `${resolve(__dirname, './src')}`,
  14. '~ass': resolve(__dirname, './src/assets'),
  15. '~com': `${resolve(__dirname, './src/components')}`,
  16. '~api': resolve(__dirname, './src/api/modules'),
  17. '~sto': resolve(__dirname, './src/store/modules'),
  18. '~uti': resolve(__dirname, './src/utils'),
  19. },
  20. },
  21. plugins: [
  22. vue({
  23. script: {
  24. defineModel: true,
  25. },
  26. }),
  27. UnoCSS(),
  28. ],
  29. build: {
  30. rollupOptions: {
  31. output: {
  32. manualChunks(id) {
  33. let libStr = '@vue,element-plus,echarts,vue-router,pinia,js-fast-way,vuedraggable,split.js,hc-vue3-ui,nprogress'
  34. const libs = libStr.split(',')
  35. if (id.includes('node_modules')) {
  36. const arr = id.toString().split('node_modules/')[1].split('/')
  37. if (libs.indexOf(arr[0]) !== -1) {
  38. return '_' + arr[0]
  39. } else {
  40. return '__vendor'
  41. }
  42. }
  43. },
  44. chunkFileNames: 'static/js1/[name]-[hash].js',
  45. entryFileNames: 'static/js2/[name]-[hash].js',
  46. assetFileNames: 'static/[ext]/[name]-[hash].[ext]',
  47. },
  48. },
  49. brotliSize: false, // 不统计
  50. target: 'esnext',
  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. })