vite.config.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import { fileURLToPath, URL } from 'node:url';
  2. import { defineConfig } from 'vite';
  3. import vue from '@vitejs/plugin-vue';
  4. import postcssPxToViewport from 'postcss-px-to-viewport';
  5. export default defineConfig({
  6. publicDir: 'public',
  7. base: './',
  8. plugins: [vue()],
  9. server: {
  10. port: '8090',
  11. host: '0.0.0.0',
  12. proxy: {
  13. '/api': {
  14. //apiTest是自行设置的请求前缀,按照这个来匹配请求,有这个字段的请求,就会进到代理来
  15. target: 'http://10.1.161.187:7878/', // 需要代理的域名
  16. secure: false,
  17. changeOrigin: true,
  18. rewrite: (path) => path.replace(/^\/api/, '') //重写匹配的字段,如果不需要放在请求路径上,可以重写为""
  19. },
  20. '/cityGIsApi': {
  21. //apiTest是自行设置的请求前缀,按照这个来匹配请求,有这个字段的请求,就会进到代理来
  22. target: 'http://10.1.161.113:18080/', // 需要代理的域名
  23. secure: false,
  24. changeOrigin: true,
  25. rewrite: (path) => path.replace(/^\/cityGIsApi/, '') //重写匹配的字段,如果不需要放在请求路径上,可以重写为""
  26. }
  27. }
  28. },
  29. resolve: {
  30. alias: {
  31. '@': fileURLToPath(new URL('./src', import.meta.url))
  32. }
  33. },
  34. css: {
  35. postcss: {
  36. plugins: [
  37. postcssPxToViewport({
  38. viewportWidth: 1950, // 视窗的宽度,对应的是我们设计稿的宽度,一般是750
  39. viewportHeight: 1080, // 视窗的高度,根据750设备的宽度来指定,一般指定1334,也可以不配置
  40. unitPrecision: 3, // 指定`px`转换为视窗单位值的小数位数(很多时候无法整除)
  41. viewportUnit: 'vw', // 指定需要转换成的视窗单位,建议使用vw
  42. fontViewportUnit: 'vw',
  43. selectorBlackList: [], // 指定不转换为视窗单位的类,可以自定义,可以无限添加,建议定义一至两个通用的类名
  44. minPixelValue: 2, // 小于或等于`1px`不转换为视窗单位,你也可以设置为你想要的值
  45. mediaQuery: true, // 允媒体查许在询中转换`px`
  46. propList: ['*', '!min-width', '!min-height'],
  47. minValue: 10
  48. // exclude:[/Tabbar/] //以Tabbar文件开头的不转化
  49. })
  50. ]
  51. }
  52. }
  53. });