vite.config.js 5.2 KB

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