vite.config.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. commonjsOptions: {
  30. transformMixedEsModules: true
  31. },
  32. chunkSizeWarningLimit: 1000,
  33. rollupOptions: {
  34. output: {
  35. // 分类输出
  36. // chunkFileNames: 'js/[name]-[hash].js',
  37. // entryFileNames: 'js/[name]-[hash].js',
  38. // assetFileNames: '[ext]/[name]-[hash].[ext]',
  39. // manualChunks(id) {
  40. // // 打包拆分js
  41. // if (id.includes('node_modules')) {
  42. // return id.toString().split('node_modules/')[1].split('/')[0].toString()
  43. // }
  44. // },
  45. },
  46. },
  47. },
  48. resolve: {
  49. alias: {
  50. '@/': new URL('./src/', import.meta.url).pathname,
  51. },
  52. },
  53. plugins: [
  54. vue2(),
  55. legacy({
  56. targets: ['ie >= 11'],
  57. additionalLegacyPolyfills: ['regenerator-runtime/runtime'],
  58. }),
  59. AutoImport({
  60. imports: [
  61. 'vue',
  62. 'vue-router',
  63. 'vuex',
  64. ],
  65. dts: false,
  66. resolvers: [],
  67. }),
  68. Components({
  69. resolvers: [
  70. ElementUiResolver(),
  71. IconsResolver({
  72. prefix: 'i',
  73. }),
  74. ],
  75. dts: false,
  76. }),
  77. Icons({
  78. // experimental
  79. 'autoInstall': true,
  80. 'my-icons': FileSystemIconLoader('./assets/icons', svg => svg),
  81. }),
  82. viteCompression({
  83. verbose: true,
  84. disable: false,
  85. deleteOriginFile: false,
  86. threshold: 10240,
  87. algorithm: 'gzip',
  88. ext: '.gz',
  89. }),
  90. visualizer({
  91. emitFile: true,
  92. filename: 'build/stats.html',
  93. open: false,
  94. gzipSize: true,
  95. brotliSize: true,
  96. }),
  97. // viteMockServe({
  98. // mockPath: 'mock',
  99. // localEnabled: command === 'serve',
  100. // prodEnabled: false,
  101. // supportTs: false,
  102. // watchFiles: true,
  103. // }),
  104. ],
  105. server: {
  106. host: "0.0.0.0",
  107. port: 8081,
  108. proxy: {},
  109. open: false,
  110. },
  111. }
  112. })