vite.config.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import {defineConfig} from 'vite'
  2. import vue from '@vitejs/plugin-vue'
  3. import {resolve} from "path";
  4. import config from "./src/config";
  5. // https://vitejs.dev/config/
  6. export default defineConfig({
  7. css: {
  8. preprocessorOptions: {
  9. scss: {
  10. additionalData: `@import "./src/styles/app/_var.scss";`
  11. }
  12. }
  13. },
  14. resolve: {
  15. alias: {
  16. '~src': `${resolve(__dirname, './src')}`,
  17. '~ass': resolve(__dirname, './src/assets'),
  18. '~com': `${resolve(__dirname, './src/components')}`,
  19. '~api': resolve(__dirname, './src/api/modules'),
  20. '~sto': resolve(__dirname, './src/store/modules'),
  21. '~uti': resolve(__dirname, './src/utils'),
  22. '~style': resolve(__dirname, './src/styles/page')
  23. }
  24. },
  25. plugins: [
  26. vue()
  27. ],
  28. build: {
  29. rollupOptions: {
  30. output: {
  31. manualChunks(id) {
  32. let libStr = '@vue,tailwindcss,element-plus,z-element-plus,echarts,vue-router,pinia,js-web-screen-shot,js-fast-way';
  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. brotliSize: false, // 不统计
  48. target: 'esnext',
  49. minify: 'esbuild' // 混淆器,terser构建后文件体积更小
  50. }
  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. })