vite.config.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. import { defineConfig } from 'vite'
  2. import legacy from '@vitejs/plugin-legacy'
  3. import vue2 from '@vitejs/plugin-vue2'
  4. // plugins
  5. import AutoImport from 'unplugin-auto-import/vite'
  6. import Components from 'unplugin-vue-components/vite'
  7. import Icons from 'unplugin-icons/vite'
  8. import IconsResolver from 'unplugin-icons/resolver'
  9. import { FileSystemIconLoader } from 'unplugin-icons/loaders'
  10. import { ElementUiResolver } from "unplugin-vue-components/resolvers";
  11. import viteCompression from 'vite-plugin-compression'
  12. import visualizer from 'rollup-plugin-visualizer'
  13. import antdvFix from 'vite-plugin-antdv-fix';
  14. import * as path from "path";
  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. '@': path.resolve(__dirname, './src'),
  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. ignore: ['h'],
  67. dts: false,
  68. resolvers: [],
  69. }),
  70. Components({
  71. resolvers: [
  72. ElementUiResolver(),
  73. IconsResolver({
  74. prefix: 'i',
  75. }),
  76. ],
  77. dts: false,
  78. }),
  79. Icons({
  80. // experimental
  81. 'autoInstall': true,
  82. 'my-icons': FileSystemIconLoader('./assets/icons', svg => svg),
  83. }),
  84. viteCompression({
  85. verbose: true,
  86. disable: false,
  87. deleteOriginFile: false,
  88. threshold: 10240,
  89. algorithm: 'gzip',
  90. ext: '.gz',
  91. }),
  92. visualizer({
  93. emitFile: true,
  94. filename: 'build/stats.html',
  95. open: false,
  96. gzipSize: true,
  97. brotliSize: true,
  98. }),
  99. antdvFix(),
  100. // viteMockServe({
  101. // mockPath: 'mock',
  102. // localEnabled: command === 'serve',
  103. // prodEnabled: false,
  104. // supportTs: false,
  105. // watchFiles: true,
  106. // }),
  107. ],
  108. server: {
  109. host: "0.0.0.0",
  110. port: 8081,
  111. proxy: {
  112. "/ioc-api": {
  113. //target: "http://127.0.0.1:10099",
  114. target: "http://10.12.242.163:10091/ioc-server",
  115. changeOrigin: true,
  116. rewrite: (path) => path.replace(/^\/ioc-api/, ""),
  117. },
  118. },
  119. open: false,
  120. },
  121. }
  122. })