vite.config.js 2.8 KB

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