vite.config.ts 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. server: {
  35. port: 6969,
  36. // open: true,
  37. https: false,
  38. host: '0.0.0.0',
  39. strictPort: false,
  40. proxy: {
  41. '/BaseMap1-api/': {
  42. // target: 'http://59.255.48.160:81/',
  43. target: 'http://127.0.0.1:3999/',
  44. changeOrigin: true,
  45. rewrite: path => {
  46. return path.replace(/^\/BaseMap1-api/, '')
  47. }
  48. },
  49. '/BaseMap2-api/': {
  50. // target: 'http://59.212.37.22/',
  51. target: 'http://127.0.0.1:3998/',
  52. changeOrigin: true,
  53. rewrite: path => {
  54. return path.replace(/^\/BaseMap2-api/, '')
  55. }
  56. },
  57. '/BaseMap3-api/': {
  58. // target: 'http://59.212.146.170/',
  59. target: 'http://127.0.0.1:3997/',
  60. changeOrigin: true,
  61. rewrite: path => {
  62. return path.replace(/^\/BaseMap3-api/, '')
  63. }
  64. },
  65. }
  66. },
  67. build: {
  68. outDir: "gis-web",
  69. rollupOptions: {//分包优化
  70. output: {
  71. manualChunks(id) {
  72. if (id.includes('node_modules')) {
  73. return time + id.toString().split('node_modules/')[1].split('/')[0].toString();
  74. } else {
  75. return time + id.toString();
  76. }
  77. // if(id.indexOf('node_modules') > -1) {
  78. // return 'vendor'
  79. // }
  80. }
  81. }
  82. }
  83. },
  84. publicDir: 'src/out',
  85. optimizeDeps: {
  86. include: []
  87. }
  88. })