vite.config.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. import { URL, fileURLToPath } from 'node:url'
  2. import { defineConfig } from 'vite'
  3. import legacy from '@vitejs/plugin-legacy'
  4. import vue2 from '@vitejs/plugin-vue2'
  5. // plugins
  6. import AutoImport from 'unplugin-auto-import/vite'
  7. import Components from 'unplugin-vue-components/vite'
  8. import Icons from 'unplugin-icons/vite'
  9. import IconsResolver from 'unplugin-icons/resolver'
  10. import { FileSystemIconLoader } from 'unplugin-icons/loaders'
  11. import { ElementUiResolver } from "unplugin-vue-components/resolvers";
  12. import viteCompression from 'vite-plugin-compression'
  13. import visualizer from 'rollup-plugin-visualizer'
  14. export default defineConfig(({ command }) => {
  15. return {
  16. base: './',
  17. assetsInclude: ['assets/'],
  18. css: {
  19. preprocessorOptions: {
  20. less: {
  21. javascriptEnabled: true,
  22. additionalData: '@import "@/style/common.less";',
  23. },
  24. },
  25. },
  26. build: {
  27. outDir: 'dist',
  28. sourcemap: false,
  29. chunkSizeWarningLimit: 1000,
  30. rollupOptions: {
  31. output: {
  32. // 分类输出
  33. // chunkFileNames: 'js/[name]-[hash].js',
  34. // entryFileNames: 'js/[name]-[hash].js',
  35. // assetFileNames: '[ext]/[name]-[hash].[ext]',
  36. // manualChunks(id) {
  37. // // 打包拆分js
  38. // if (id.includes('node_modules')) {
  39. // return id.toString().split('node_modules/')[1].split('/')[0].toString()
  40. // }
  41. // },
  42. },
  43. },
  44. },
  45. resolve: {
  46. alias: {
  47. '@/': new URL('./src/', import.meta.url).pathname,
  48. },
  49. },
  50. plugins: [
  51. vue2(),
  52. legacy({
  53. targets: ['ie >= 11'],
  54. additionalLegacyPolyfills: ['regenerator-runtime/runtime'],
  55. }),
  56. AutoImport({
  57. imports: [
  58. 'vue',
  59. 'vue-router',
  60. 'vuex',
  61. ],
  62. dts: false,
  63. resolvers: [],
  64. }),
  65. Components({
  66. resolvers: [
  67. ElementUiResolver(),
  68. IconsResolver({
  69. prefix: 'i',
  70. }),
  71. ],
  72. dts: false,
  73. }),
  74. Icons({
  75. // experimental
  76. 'autoInstall': true,
  77. 'my-icons': FileSystemIconLoader('./assets/icons', svg => svg),
  78. }),
  79. viteCompression({
  80. verbose: true,
  81. disable: false,
  82. deleteOriginFile: false,
  83. threshold: 10240,
  84. algorithm: 'gzip',
  85. ext: '.gz',
  86. }),
  87. visualizer({
  88. emitFile: true,
  89. filename: 'build/stats.html',
  90. open: false,
  91. gzipSize: true,
  92. brotliSize: true,
  93. }),
  94. // viteMockServe({
  95. // mockPath: 'mock',
  96. // localEnabled: command === 'serve',
  97. // prodEnabled: false,
  98. // supportTs: false,
  99. // watchFiles: true,
  100. // }),
  101. ],
  102. server: {
  103. host: "0.0.0.0",
  104. port: 8081,
  105. proxy: {},
  106. open: false,
  107. },
  108. }
  109. })