vite.config.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. import commonjs from 'vite-plugin-commonjs';
  6. // https://vitejs.dev/config/
  7. export default defineConfig({
  8. plugins: [
  9. vue(),
  10. commonjs({
  11. include: /utils\/map\/CityGis.Bridge.js/, // 包含的文件路径
  12. exclude: [], // 排除的文件路径
  13. extensions: ['.js'], // 需要转换的文件扩展名
  14. ignoreGlobal: false, // 是否忽略全局变量(例如 Buffer)
  15. sourceMap: false, // 是否生成源映射
  16. namedExports: {}, // 命名导出(名称和值)
  17. ignore: [], // 忽略文件的正则表达式
  18. transformMixedEsModules: true // 是否转换混合的 ES 模块
  19. })
  20. ],
  21. server: {
  22. port: '8090',
  23. host: '0.0.0.0',
  24. proxy: {
  25. '/api': {
  26. //apiTest是自行设置的请求前缀,按照这个来匹配请求,有这个字段的请求,就会进到代理来
  27. target: 'http://10.1.161.180:7878/', // 需要代理的域名
  28. secure: false,
  29. changeOrigin: true,
  30. rewrite: (path) => path.replace(/^\/api/, '') //重写匹配的字段,如果不需要放在请求路径上,可以重写为""
  31. },
  32. '/cityGIsApi': {
  33. //apiTest是自行设置的请求前缀,按照这个来匹配请求,有这个字段的请求,就会进到代理来
  34. target: 'http://10.1.161.113:18080/', // 需要代理的域名
  35. secure: false,
  36. changeOrigin: true,
  37. rewrite: (path) => path.replace(/^\/cityGIsApi/, '') //重写匹配的字段,如果不需要放在请求路径上,可以重写为""
  38. }
  39. // '^/citygis-gateway': {
  40. // //apiTest是自行设置的请求前缀,按照这个来匹配请求,有这个字段的请求,就会进到代理来
  41. // target: 'http://10.1.161.53:30080/', // 需要代理的域名
  42. // secure: false,
  43. // changeOrigin: true,
  44. // rewrite: (path) => path.replace(/^\/citygis-gateway/, 'citygis-gateway/')
  45. // }
  46. }
  47. },
  48. resolve: {
  49. alias: {
  50. '@': fileURLToPath(new URL('./src', import.meta.url))
  51. }
  52. },
  53. css: {
  54. postcss: {
  55. plugins: [
  56. postcssPxToViewport({
  57. viewportWidth: 1950, // 视窗的宽度,对应的是我们设计稿的宽度,一般是750
  58. viewportHeight: 1080, // 视窗的高度,根据750设备的宽度来指定,一般指定1334,也可以不配置
  59. unitPrecision: 3, // 指定`px`转换为视窗单位值的小数位数(很多时候无法整除)
  60. viewportUnit: 'vw', // 指定需要转换成的视窗单位,建议使用vw
  61. fontViewportUnit: 'vw',
  62. selectorBlackList: [], // 指定不转换为视窗单位的类,可以自定义,可以无限添加,建议定义一至两个通用的类名
  63. minPixelValue: 2, // 小于或等于`1px`不转换为视窗单位,你也可以设置为你想要的值
  64. mediaQuery: true, // 允媒体查许在询中转换`px`
  65. propList: ['*', '!min-width', '!min-height'],
  66. minValue: 10
  67. // exclude:[/Tabbar/] //以Tabbar文件开头的不转化
  68. })
  69. ]
  70. }
  71. }
  72. });