vite.config.ts 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. import { defineConfig } from 'vite'
  2. import vue from '@vitejs/plugin-vue'
  3. import topLevelAwait from 'vite-plugin-top-level-await'
  4. import { resolve } from 'path'
  5. import viteCompression from 'vite-plugin-compression';//Gzip
  6. import { visualizer } from "rollup-plugin-visualizer";
  7. import { createSvgIconsPlugin } from 'vite-plugin-svg-icons' // 【svg-icons相关】
  8. import VitePluginHtmlEnv from 'vite-plugin-html-env'
  9. const time = new Date().getTime()
  10. // @ts-ignore
  11. // https://vitejs.dev/config/
  12. export default defineConfig({
  13. define: {
  14. 'process.env': process.env
  15. },
  16. plugins: [vue(), viteCompression(), VitePluginHtmlEnv(), visualizer(), createSvgIconsPlugin({
  17. // 指定需要缓存的图标文件夹
  18. iconDirs: [resolve(process.cwd(), 'src/assets/svg/global'), resolve(process.cwd(), 'src/assets/svg/business')],
  19. // 指定symbolId格式
  20. symbolId: 'icon-[dir]-[name]',
  21. }), topLevelAwait({
  22. promiseExportName: '__tla',
  23. promiseImportName: i => `__tla_${i}`
  24. })],
  25. base: '/',
  26. resolve: {
  27. alias: {
  28. '@': resolve(__dirname, 'src'),
  29. '~@': resolve(__dirname, 'src'),
  30. '@views': resolve(__dirname, 'src/views'),
  31. '@components': resolve(__dirname, 'src/components')
  32. },
  33. },
  34. esbuild: {
  35. jsxFactory: 'h',
  36. jsxFragment: 'Fragment',
  37. jsxInject: "import { h } from 'vue';"
  38. },
  39. server: {
  40. port: 6969,
  41. // open: true,
  42. https: false,
  43. host: '0.0.0.0',
  44. strictPort: false,
  45. proxy: {
  46. '/BaseMap1-api/': {
  47. // target: 'http://59.255.48.160:81/',
  48. target: 'http://127.0.0.1:3999/',
  49. changeOrigin: true,
  50. rewrite: path => {
  51. return path.replace(/^\/BaseMap1-api/, '')
  52. }
  53. },
  54. '/BaseMap2-api/': {
  55. // target: 'http://59.212.37.22/',
  56. target: 'http://127.0.0.1:3998/',
  57. changeOrigin: true,
  58. rewrite: path => {
  59. return path.replace(/^\/BaseMap2-api/, '')
  60. }
  61. },
  62. '/BaseMap3-api/': {
  63. // target: 'http://59.212.146.170/',
  64. target: 'http://127.0.0.1:3997/',
  65. changeOrigin: true,
  66. rewrite: path => {
  67. return path.replace(/^\/BaseMap3-api/, '')
  68. }
  69. },
  70. '/business-api/': {
  71. // target: 'http://192.168.31.26:7074/',
  72. target: 'http://8.140.240.182:18087/',
  73. changeOrigin: true,
  74. rewrite: path => {
  75. return path.replace(/^\/business-api/, '')
  76. }
  77. },
  78. '/geoserver-api/': {
  79. target: 'http://8.141.90.117:18092/',
  80. changeOrigin: true,
  81. rewrite: path => {
  82. return path.replace(/^\/geoserver-api/, '')
  83. }
  84. },
  85. }
  86. },
  87. build: {
  88. outDir: "gis-web",
  89. rollupOptions: {//分包优化
  90. output: {
  91. manualChunks(id) {
  92. if (id.includes('node_modules')) {
  93. return time + id.toString().split('node_modules/')[1].split('/')[0].toString();
  94. } else {
  95. return time + id.toString();
  96. }
  97. // if(id.indexOf('node_modules') > -1) {
  98. // return 'vendor'
  99. // }
  100. }
  101. }
  102. }
  103. },
  104. publicDir: 'src/out',
  105. optimizeDeps: {
  106. include: []
  107. }
  108. })