vite.config.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. import * as path from "path";
  2. import postcsspxtoviewport8plugin from 'postcss-px-to-viewport-8-plugin'
  3. const resolve = (dir) => path.resolve(__dirname, dir);
  4. import { fileURLToPath, URL } from 'node:url'
  5. import { defineConfig } from 'vite'
  6. import vue from '@vitejs/plugin-vue'
  7. import AutoImport from 'unplugin-auto-import/vite'
  8. import Components from 'unplugin-vue-components/vite'
  9. import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
  10. // https://vitejs.dev/config/
  11. export default defineConfig({
  12. server:{
  13. cors: true,
  14. proxy: {
  15. '^/api-v2': {
  16. // 代理请求之后的请求地址(你的真实接口地址)
  17. target: 'https://cimweb.zjw.sh.cegn.cn:2007/data-business-prod-2/',
  18. //target: 'http://192.168.3.32:9250/',
  19. secure: false,
  20. ws: true,
  21. // 跨域
  22. changeOrigin: true,
  23. rewrite: (path) => path.replace(/^\/api-v2/, ''),
  24. configure: (proxy) => {
  25. proxy.on('proxyReq', function (proxyReq) {
  26. proxyReq.removeHeader('referer')
  27. proxyReq.removeHeader('origin')
  28. proxyReq.setHeader('host','cimweb.zjw.sh.cegn.cn:2007')
  29. })
  30. },
  31. },
  32. // 代理所有 /api 的请求,该求情将被代理到 target 中
  33. '/api': {
  34. // 代理请求之后的请求地址(你的真实接口地址)
  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. },
  43. '/addressapi': {
  44. // 代理请求之后的请求地址(你的真实接口地址)
  45. target: 'https://cimweb.zjw.sh.cegn.cn:2008/',
  46. // target: 'http://localhost:9250/',
  47. secure: false,
  48. ws: true,
  49. // 跨域
  50. changeOrigin: true,
  51. rewrite: (path) => path.replace(/^\/addressapi/, '')
  52. }
  53. },
  54. },
  55. css:{
  56. postcss:{
  57. plugins:[
  58. postcsspxtoviewport8plugin({
  59. unitToConvert: 'px', // 要转化的单位
  60. viewportWidth: 1920, // UI设计稿的宽度
  61. unitPrecision: 6, // 转换后的精度,即小数点位数
  62. propList: [
  63. 'width',
  64. 'left',
  65. 'right',
  66. 'font-size',
  67. 'margin-left',
  68. 'margin-right',
  69. 'text-indent',
  70. 'padding-left',
  71. 'padding-right',
  72. 'padding',
  73. ], // 指定转换的css属性的单位,*代表全部css属性的单位都进行转换
  74. viewportUnit: 'vw', // 指定需要转换成的视窗单位,默认vw
  75. fontViewportUnit: 'vw', // 指定字体需要转换成的视窗单位,默认vw
  76. selectorBlackList: ['ignore-'], // 指定不转换为视窗单位的类名
  77. minPixelValue: 1, // 默认值1,小于或等于1px则不进行转换
  78. mediaQuery: true, // 是否在媒体查询的css代码中也进行转换,默认false
  79. replace: true, // 是否转换后直接更换属性值
  80. exclude: [/node_modules/], // 设置忽略文件,用正则做目录名匹配
  81. // exclude: [],
  82. include: [
  83. /\/src\/pages\/amap\/factor-monitor.vue/,
  84. ],
  85. landscape: false, // 是否处理横屏情况
  86. }),
  87. // 处理属性转vh的情况
  88. postcsspxtoviewport8plugin({
  89. unitToConvert: 'px', // 要转化的单位
  90. viewportWidth: 1080, // UI设计稿的宽度
  91. unitPrecision: 6, // 转换后的精度,即小数点位数
  92. propList: [
  93. 'height',
  94. 'top',
  95. 'bottom',
  96. 'margin-top',
  97. 'margin-bottom',
  98. 'padding-top',
  99. 'padding-bottom',
  100. 'line-height',
  101. ], // 指定转换的css属性的单位,*代表全部css属性的单位都进行转换
  102. viewportUnit: 'vh', // 指定需要转换成的视窗单位,默认vw
  103. fontViewportUnit: 'vh', // 指定字体需要转换成的视窗单位,默认vw
  104. selectorBlackList: ['ignore-'], // 指定不转换为视窗单位的类名
  105. minPixelValue: 1, // 默认值1,小于或等于1px则不进行转换
  106. mediaQuery: true, // 是否在媒体查询的css代码中也进行转换,默认false
  107. replace: true, // 是否转换后直接更换属性值
  108. exclude: [/node_modules/], // 设置忽略文件,用正则做目录名匹配
  109. // exclude: [],
  110. include: [
  111. /\/src\/pages\/amap\/factor-monitor.vue/,
  112. ],
  113. landscape: false, // 是否处理横屏情况
  114. })
  115. ]
  116. }
  117. },
  118. //https:true,
  119. plugins: [vue(), AutoImport({
  120. resolvers: [ElementPlusResolver()],
  121. }),
  122. Components({
  123. resolvers: [ElementPlusResolver()],
  124. }),],
  125. base:'./',
  126. build:{
  127. outDir:'space-share-exchange'
  128. },
  129. publicDir: resolve('static'),
  130. resolve: {
  131. alias: {
  132. '@': fileURLToPath(new URL('./src', import.meta.url))
  133. }
  134. }
  135. })