vite.config.js 3.2 KB

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