You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
2.3 KiB

2 months ago
2 months ago
2 months ago
2 months ago
  1. import {defineConfig, loadEnv} from 'vite'
  2. import vue from '@vitejs/plugin-vue'
  3. import {lazyImport, VxeResolver} from 'vite-plugin-lazy-import'
  4. import legacy from '@vitejs/plugin-legacy'
  5. import path from 'path'
  6. import {visualizer} from 'rollup-plugin-visualizer'
  7. // https://vite.dev/config/
  8. export default defineConfig(({mode}) => {
  9. const env = loadEnv(mode, process.cwd())
  10. console.log('当前环境:', mode)
  11. console.log('当前环境变量:', env)
  12. return {
  13. esbuild: {
  14. supported: {
  15. bigint: true
  16. },
  17. treeShaking: true,
  18. drop: ['console', 'debugger'],
  19. },
  20. plugins: [
  21. vue(),
  22. visualizer({
  23. open: true, // 打包完成后自动展示
  24. gzipSize: true, // 显示gzip压缩后的大小
  25. brotliSize: true // 显示brotli压缩后的大小
  26. }),
  27. legacy({
  28. targets: ['defaults', 'not IE 11', 'chrome >=73'],
  29. modernPolyfills: true
  30. }),
  31. lazyImport({
  32. resolvers: [
  33. VxeResolver({
  34. libraryName: 'vxe-table'
  35. }),
  36. VxeResolver({
  37. libraryName: 'vxe-pc-ui'
  38. })
  39. ]
  40. })
  41. ],
  42. server: {
  43. host: true // 允许外部设备访问
  44. },
  45. resolve: {
  46. alias: {
  47. '@': path.resolve(__dirname, './src')
  48. }
  49. },
  50. base: process.env.NODE_ENV === 'production' ? './' : '/',
  51. build: {
  52. sourcemap: false, // 关闭 sourcemap
  53. minify: 'terser',
  54. terserOptions: {
  55. compress: {
  56. drop_console: true, // 生产环境去除console
  57. drop_debugger: true // 生产环境去除 debugger
  58. }
  59. },
  60. rollupOptions: {
  61. output: {
  62. manualChunks: {
  63. echarts: ['echarts'],
  64. xlsx: ['xlsx'],
  65. lodash: ['lodash'],
  66. vue: ['vue', 'vue-router', 'pinia'],
  67. elementPlus: ['element-plus']
  68. }
  69. }
  70. }
  71. }
  72. }
  73. })