vite.config.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. preprocessorOptions: {
  10. scss: {
  11. additionalData: '@import "./src/styles/app/_var.scss";',
  12. },
  13. },
  14. },
  15. resolve: {
  16. alias: {
  17. '~src': `${resolve(__dirname, './src')}`,
  18. '~ass': resolve(__dirname, './src/assets'),
  19. '~com': `${resolve(__dirname, './src/components')}`,
  20. '~api': resolve(__dirname, './src/api/modules'),
  21. '~sto': resolve(__dirname, './src/store/modules'),
  22. '~uti': resolve(__dirname, './src/utils'),
  23. '~style': resolve(__dirname, './src/styles/page'),
  24. },
  25. },
  26. plugins: [
  27. vue(),
  28. UnoCSS(),
  29. ],
  30. build: {
  31. target: 'esnext', // 设置构建目标
  32. minify: 'esbuild', // 使用 esbuild 进行压缩
  33. chunkSizeWarningLimit: 1000, // 将警告的阈值提高到 1000 KB
  34. rollupOptions: {
  35. output: {
  36. manualChunks(id) {
  37. let libStr = '@vue,hc-vue3-ui,element-plus,z-element-plus,echarts,vue-router,pinia,js-web-screen-shot,js-fast-way'
  38. const libs = libStr.split(',')
  39. if (id.includes('node_modules')) {
  40. const arr = id.toString().split('node_modules/')[1].split('/')
  41. if (libs.indexOf(arr[0]) !== -1) {
  42. return '_' + arr[0]
  43. } else {
  44. return '__vendor'
  45. }
  46. }
  47. },
  48. chunkFileNames: 'static/js1/[name]-[hash].js',
  49. entryFileNames: 'static/js2/[name]-[hash].js',
  50. assetFileNames: 'static/[ext]/[name]-[hash].[ext]',
  51. },
  52. },
  53. },
  54. server: {
  55. ...config.vite,
  56. proxy: {
  57. '/api': {
  58. ws: true,
  59. changeOrigin: true,
  60. target: config.target,
  61. rewrite: (path) => path.replace(new RegExp('^/api'), '/'),
  62. },
  63. },
  64. },
  65. })