vite.config.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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://datamidplat.zjw.sh.cegn.cn:2011/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','datamidplat.zjw.sh.cegn.cn:2011')
  28. })
  29. },
  30. }
  31. },
  32. },
  33. publicDir: "public",
  34. base: './',
  35. plugins: [
  36. vue(),
  37. commonjs({
  38. exclude: [], // 排除的文件路径
  39. extensions: ['.js'], // 需要转换的文件扩展名
  40. ignoreGlobal: false, // 是否忽略全局变量(例如 Buffer)
  41. sourceMap: false, // 是否生成源映射
  42. namedExports: {}, // 命名导出(名称和值)
  43. ignore: [], // 忽略文件的正则表达式
  44. transformMixedEsModules: true, // 是否转换混合的 ES 模块
  45. }),
  46. AutoImport({
  47. resolvers: [ElementPlusResolver()],
  48. }),
  49. Components({
  50. resolvers: [ElementPlusResolver()],
  51. }),
  52. ],
  53. build: {
  54. outDir: 'data-middleground',
  55. },
  56. resolve: {
  57. alias: {
  58. '@': fileURLToPath(new URL('./src', import.meta.url))
  59. }
  60. }
  61. })