8
0

vite.config.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. UnoCSS(),
  24. ],
  25. build: {
  26. sourcemap: false,
  27. rollupOptions: {
  28. output: {
  29. manualChunks(id) {
  30. let libStr = `
  31. @vue,vue-router,pinia,hc-vue3-ui,js-fast-way,element-plus, @vojtechlanka/vue-tags-input,
  32. echarts,split.js,nprogress,avue-plugin-ueditor,@smallwei/avue`
  33. const libs = libStr.split(',')
  34. if (id.includes('node_modules')) {
  35. const arr = id.toString().split('node_modules/')[1].split('/')
  36. if (libs.indexOf(arr[0]) !== -1) {
  37. return '_' + arr[0]
  38. } else {
  39. return '__vendor'
  40. }
  41. }
  42. },
  43. chunkFileNames: 'static/js1/[name]-[hash].js',
  44. entryFileNames: 'static/js2/[name]-[hash].js',
  45. assetFileNames: 'static/[ext]/[name]-[hash].[ext]',
  46. },
  47. },
  48. brotliSize: false, // 不统计
  49. target: 'esnext',
  50. },
  51. server: {
  52. ...config.vite,
  53. proxy: {
  54. '/api': {
  55. ws: true,
  56. changeOrigin: true,
  57. target: config.target,
  58. rewrite: (path) => path.replace(new RegExp('^/api'), '/'),
  59. },
  60. },
  61. },
  62. })