vite.config.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 的请求,该求情将被代理到 target 中
  14. '/api': {
  15. // 代理请求之后的请求地址(你的真实接口地址)
  16. target: 'https://cimweb.zjw.sh.cegn.cn:2007/data-business-prod/',
  17. // target: 'http://localhost:9250/',
  18. secure: false,
  19. ws: true,
  20. // 跨域
  21. changeOrigin: true,
  22. rewrite: (path) => path.replace(/^\/api/, ''),
  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. },
  32. },
  33. publicDir: "public",
  34. base: './',
  35. plugins: [
  36. vue(),
  37. commonjs({
  38. include: /static\/clay.min.js/, // 包含的文件路径
  39. exclude: [], // 排除的文件路径
  40. extensions: ['.js'], // 需要转换的文件扩展名
  41. ignoreGlobal: false, // 是否忽略全局变量(例如 Buffer)
  42. sourceMap: false, // 是否生成源映射
  43. namedExports: {}, // 命名导出(名称和值)
  44. ignore: [], // 忽略文件的正则表达式
  45. transformMixedEsModules: true, // 是否转换混合的 ES 模块
  46. }),
  47. AutoImport({
  48. resolvers: [ElementPlusResolver()],
  49. }),
  50. Components({
  51. resolvers: [ElementPlusResolver()],
  52. }),
  53. ],
  54. build: {
  55. outDir: 'cim-my-home',
  56. commonjsOptions: {
  57. include: /node_modules|static\/CityGis.Bridge.js/,
  58. }
  59. },
  60. resolve: {
  61. alias: {
  62. '@': fileURLToPath(new URL('./src', import.meta.url))
  63. }
  64. }
  65. })