vite.config.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import { defineConfig } from 'vite'
  2. import vue from '@vitejs/plugin-vue'
  3. import { resolve } from 'path'
  4. import config from './src/config'
  5. import { sentryVitePlugin } from '@sentry/vite-plugin'
  6. // https://vitejs.dev/config/
  7. export default defineConfig({
  8. css: {
  9. extract: true,
  10. preprocessorOptions: {
  11. scss: {
  12. additionalData: '@import "./src/styles/app/_var.scss";',
  13. },
  14. },
  15. },
  16. resolve: {
  17. alias: {
  18. '~src': `${resolve(__dirname, './src')}`,
  19. '~ass': resolve(__dirname, './src/assets'),
  20. '~com': `${resolve(__dirname, './src/components')}`,
  21. '~api': resolve(__dirname, './src/api/modules'),
  22. '~sto': resolve(__dirname, './src/store/modules'),
  23. '~uti': resolve(__dirname, './src/utils'),
  24. },
  25. },
  26. plugins: [
  27. vue(),
  28. sentryVitePlugin({
  29. org: 'hongc',
  30. project: 'for_client',
  31. url: 'http://192.168.0.109:5501',
  32. authToken: 'e621ebf80f2e12a7dd1a353b10b7a848506eb43fd268093bbc4fb0822cd5cd0c',
  33. sourcemaps: {
  34. filesToDeleteAfterUpload: ['dist/**/*.js.map'],
  35. },
  36. }),
  37. ],
  38. build: {
  39. sourcemap: true,
  40. rollupOptions: {
  41. output: {
  42. manualChunks(id) {
  43. let libStr = '@vue,tailwindcss,element-plus,z-element-plus,echarts,vue-router,pinia,js-web-screen-shot,js-fast-way'
  44. const libs = libStr.split(',')
  45. if (id.includes('node_modules')) {
  46. const arr = id.toString().split('node_modules/')[1].split('/')
  47. if (libs.indexOf(arr[0]) !== -1) {
  48. return '_' + arr[0]
  49. } else {
  50. return '__vendor'
  51. }
  52. }
  53. },
  54. chunkFileNames: 'static/js1/[name]-[hash].js',
  55. entryFileNames: 'static/js2/[name]-[hash].js',
  56. assetFileNames: 'static/[ext]/[name]-[hash].[ext]',
  57. },
  58. sourcemap: true,
  59. brotliSize: false, // 不统计
  60. target: 'esnext',
  61. minify: 'esbuild', // 混淆器,terser构建后文件体积更小
  62. },
  63. },
  64. server: {
  65. ...config.vite,
  66. proxy: {
  67. '/api': {
  68. ws: true,
  69. changeOrigin: true,
  70. target: config.target,
  71. rewrite: (path) => path.replace(new RegExp('^/api'), '/'),
  72. },
  73. },
  74. },
  75. })