vite.config.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import { fileURLToPath, URL } from 'node:url'
  2. import { defineConfig } from 'vite'
  3. import vue from '@vitejs/plugin-vue'
  4. import AutoImport from 'unplugin-auto-import/vite'
  5. import Components from 'unplugin-vue-components/vite'
  6. import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
  7. import commonjs from 'vite-plugin-commonjs';
  8. // https://vitejs.dev/config/
  9. export default defineConfig({
  10. publicDir: "public",
  11. base: './',
  12. server: {
  13. open: true,
  14. cors: true,
  15. proxy: {
  16. // 代理所有 /api 的请求,该求情将被代理到 target 中
  17. '/api2': {
  18. // 代理请求之后的请求地址(你的真实接口地址)
  19. // target: 'http://10.108.3.5:8080/cmnw_server_dev/api',
  20. target: 'http://10.244.107.145:8081/cmnw_server_dev/api',
  21. secure: false,
  22. ws: true,
  23. // 跨域
  24. changeOrigin: true,
  25. rewrite: (path) => path.replace(/^\/api2/, ''),
  26. configure: (proxy) => {
  27. proxy.on('proxyReq', function (proxyReq) {
  28. proxyReq.removeHeader('referer')
  29. proxyReq.removeHeader('origin')
  30. proxyReq.setHeader('host','10.108.3.5:8080')
  31. // proxyReq.setHeader('host','10.244.107.145:8081')
  32. })
  33. },
  34. },
  35. '/api3': {
  36. // 代理请求之后的请求地址(你的真实接口地址)
  37. target: 'http://10.108.3.5:8080',
  38. // target: 'http://61.172.176.217:8081/',
  39. secure: false,
  40. ws: true,
  41. // 跨域
  42. changeOrigin: true,
  43. rewrite: (path) => path.replace(/^\/api3/, ''),
  44. // configure: (proxy) => {
  45. // proxy.on('proxyReq', function (proxyReq) {
  46. // proxyReq.removeHeader('referer')
  47. // proxyReq.removeHeader('origin')
  48. // // proxyReq.setHeader('host','10.108.3.5:8080')
  49. // proxyReq.setHeader('host','10.244.107.145:8081')
  50. // })
  51. // },
  52. },
  53. },
  54. // port: 8080,
  55. },
  56. plugins: [
  57. vue(),
  58. AutoImport({
  59. resolvers: [ElementPlusResolver()],
  60. }),
  61. Components({
  62. resolvers: [ElementPlusResolver()],
  63. }),
  64. commonjs({
  65. include: /utils\/map\/CityGis.Bridge.js/, // 包含的文件路径
  66. exclude: [], // 排除的文件路径
  67. extensions: ['.js'], // 需要转换的文件扩展名
  68. ignoreGlobal: false, // 是否忽略全局变量(例如 Buffer)
  69. sourceMap: false, // 是否生成源映射
  70. namedExports: {}, // 命名导出(名称和值)
  71. ignore: [], // 忽略文件的正则表达式
  72. transformMixedEsModules: true, // 是否转换混合的 ES 模块
  73. })
  74. ],
  75. build: {
  76. outDir: 'cmnw_xmsb',
  77. commonjsOptions: {
  78. include: /node_modules|utils\/map\/CityGis.Bridge.js/,
  79. }
  80. },
  81. resolve: {
  82. alias: {
  83. '@': fileURLToPath(new URL('./src', import.meta.url))
  84. }
  85. }
  86. })