vite.config.js 3.1 KB

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