vite.config.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. '~api': resolve(__dirname, './src/api/modules'),
  15. '~store': resolve(__dirname, './src/store/modules'),
  16. },
  17. },
  18. plugins: [
  19. vue(),
  20. UnoCSS(),
  21. ],
  22. build: {
  23. sourcemap: false,
  24. rollupOptions: {
  25. output: {
  26. manualChunks(id) {
  27. let libStr = `
  28. @vue,vue-router,pinia,hc-vue3-ui,js-fast-way,element-plus
  29. echarts,vuedraggable,unocss,nprogress,unocss-preset-extra`
  30. const libs = libStr.split(',')
  31. if (id.includes('node_modules')) {
  32. const arr = id.toString().split('node_modules/')[1].split('/')
  33. if (libs.indexOf(arr[0]) !== -1) {
  34. return '_' + arr[0]
  35. } else {
  36. return '__vendor'
  37. }
  38. }
  39. },
  40. chunkFileNames: 'static/js1/[name]-[hash].js',
  41. entryFileNames: 'static/js2/[name]-[hash].js',
  42. assetFileNames: 'static/[ext]/[name]-[hash].[ext]',
  43. },
  44. },
  45. brotliSize: false, // 不统计
  46. target: 'esnext',
  47. },
  48. server: {
  49. ...config.vite,
  50. proxy: {
  51. '/api': {
  52. ws: true,
  53. changeOrigin: true,
  54. target: config.target,
  55. rewrite: (path) => path.replace(new RegExp('^/api'), '/'),
  56. },
  57. },
  58. },
  59. })