前端转vue
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

vite.config.ts 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. import { fileURLToPath, URL } from 'node:url'
  2. import { defineConfig } from 'vite'
  3. import vue from '@vitejs/plugin-vue'
  4. import vueJsx from '@vitejs/plugin-vue-jsx'
  5. import path from 'path';
  6. import { createSvgIconsPlugin } from 'vite-plugin-svg-icons';
  7. import { vite2Ext } from "apite";
  8. // 自动动态引入antv组件,测试结果发现全部引入也不大,所以注了
  9. // import Components from 'unplugin-vue-components/vite';
  10. // import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers';
  11. import OptimizationPersist from 'vite-plugin-optimize-persist'
  12. import PkgConfig from 'vite-plugin-package-config'
  13. import vueSetupExtend from 'vite-plugin-vue-setup-extend'
  14. import { visualizer } from 'rollup-plugin-visualizer'
  15. const lifecycle = process.env.npm_lifecycle_event;
  16. // https://vitejs.dev/config/
  17. export default defineConfig({
  18. esbuild: {
  19. drop: [],
  20. },
  21. build: {
  22. sourcemap: true,
  23. // terserOptions: {
  24. // compress: {
  25. // drop_console: false,
  26. // drop_debugger: false,
  27. // },
  28. // },
  29. chunkSizeWarningLimit: 5000,
  30. rollupOptions: {
  31. output: {
  32. // manualChunks: {
  33. // vendor
  34. // },
  35. chunkFileNames: 'js/[name]-[hash].js',
  36. entryFileNames: 'js/[name]-[hash].js',
  37. assetFileNames: '[ext]/[name]-[hash].[ext]',
  38. manualChunks(id) { //静态资源分拆打包
  39. // 可参考https://www.cnblogs.com/jyk/p/16029074.html
  40. // node包插件打包在一起
  41. if (id.includes('node_modules')) {
  42. const arr = id.toString().split('node_modules/')[1].split('/')
  43. switch (arr[0]) {
  44. // logicflow是例外,和页面文件打包在一起
  45. case '@logicflow':
  46. // if (arr[1] === 'core') {
  47. // return 'logicflow_core'
  48. // } else {
  49. // return 'logicflow_extension'
  50. // }
  51. break;
  52. default:
  53. return 'vendors'
  54. }
  55. }
  56. }
  57. },
  58. },
  59. },
  60. plugins: [
  61. vue(),
  62. vueJsx(),
  63. createSvgIconsPlugin({
  64. // 指定需要缓存的图标文件夹
  65. iconDirs: [path.resolve(process.cwd(), 'src/assets/icons')],
  66. // 指定symbolId格式
  67. symbolId: 'icon-[dir]-[name]',
  68. }),
  69. vite2Ext({
  70. dir: 'mock'
  71. }) as any,
  72. // Components({
  73. // dts: true,
  74. // resolvers: [AntDesignVueResolver()],
  75. // include: [/\.vue$/, /\.tsx$/],
  76. // }),
  77. PkgConfig(),
  78. OptimizationPersist(),
  79. vueSetupExtend(),
  80. lifecycle === 'report' ? visualizer({ gzipSize: true, open: true, brotliSize: true, filename: 'report.html' }) : null
  81. ],
  82. resolve: {
  83. alias: [
  84. {
  85. find: 'vue-i18n',
  86. replacement: 'vue-i18n/dist/vue-i18n.cjs.js',
  87. },
  88. {
  89. find: '@',
  90. replacement: fileURLToPath(new URL('./src', import.meta.url))
  91. }
  92. ],
  93. },
  94. server: {
  95. port: 9102,
  96. proxy: {
  97. //-----------------------------财务请求代理--------------------------------
  98. '/zz-pack': {
  99. // target: 'http://localhost:8090/zz-pack/',
  100. target: 'http://192.168.1.206:12206/zz-pack/',
  101. changeOrigin: true,
  102. rewrite: (path) => path.replace(/^\/zz-pack/, '')
  103. },
  104. '/zz_rpt': {
  105. // target: 'http://localhost:8090/zz-pack/',
  106. target: 'http://192.168.1.206:12206/zz-pack/',
  107. changeOrigin: true,
  108. rewrite: (path) => path.replace(/^\/zz-pack/, '')
  109. },
  110. //-------------------------------工作流请求代理--------------------------------
  111. '/dhcFlowable': {
  112. //target: 'http://114.116.37.212:9043/dhcc_flow',
  113. target: ' http://172.16.2.34:7888/cwsys-service/',
  114. changeOrigin: true,
  115. rewrite: (path) => path.replace(/^/, '')
  116. },
  117. //-------------------------------前端模拟数据使用--------------------------
  118. '/workflow/api': {
  119. target: 'http://localhost:8888/',
  120. changeOrigin: true,
  121. rewrite: (path) => path.replace(/^\/workflow\/api/, '')
  122. }
  123. },
  124. },
  125. css: {
  126. preprocessorOptions: {
  127. less: {
  128. // modifyVars: generateModifyVars(),
  129. javascriptEnabled: true,
  130. },
  131. },
  132. },
  133. })