vite.config.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. extract: true,
  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. },
  24. },
  25. plugins: [
  26. vue(),
  27. ],
  28. build: {
  29. sourcemap: true,
  30. rollupOptions: {
  31. output: {
  32. manualChunks(id) {
  33. let libStr = '@vue,tailwindcss,element-plus,z-element-plus,echarts,vue-router,pinia,js-web-screen-shot,js-fast-way'
  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. sourcemap: true,
  49. brotliSize: false, // 不统计
  50. target: 'esnext',
  51. minify: 'esbuild', // 混淆器,terser构建后文件体积更小
  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. })