import { defineConfig } from 'vite' import react from '@vitejs/plugin-react' import postcssPxToViewport from 'postcss-px-to-viewport'; import legacy from "@vitejs/plugin-legacy"; // import commonjs from 'vite-plugin-commonjs'; export default defineConfig({ // base:'/car-shop3/', // 设置为相对路径 base:'/h5/', // 设置为相对路径 plugins: [ react(), legacy({ targets: ["ie>=11"], additionalLegacyPolyfills: ["regenerator-runtime/runtime"], }), ], // server: { // proxy: { // '/api': { // target: 'http://localhost:3000', // 目标服务器的地址 // changeOrigin: true, // 是否改变源地址 // rewrite: (path) => path.replace(/^\/api/, '') // 路径重写,将/api替换为空 // } // } // }, // build: { // commonjsOptions: { // transformMixedEsModules: true // } // }, build: { // outDir: 'dist/h5',// 输出目录设置为 dist/h5 assetsDir: 'assets', }, server: { host: '0.0.0.0', // 允许外部网络访问 port: 3000, // 更改此处的端口号 }, resolve: { alias: { '@': '/src', // 配置@指向src目录 }, }, css: { postcss: { plugins: [ postcssPxToViewport({ viewportWidth: 375, // 视口宽度,根据设计图的大小 viewportHeight: 1000, // 视口高度,根据设计图的大小 unitPrecision: 6,// 保留小数点 viewportUnit: 'vw', // 单位 selectorBlackList: [], // 排除的类 minPixelValue: 1, // px的最小单位 mediaQuery: false, // 排除媒体查询 landscapeUnit: 'vw', // 横屏单位 fontViewportUnit: 'vw', // 字体属性单位 // exclude: /(\/|\\)(node_modules)(\/|\\)/, // 排除 node_modules 目录下的文件 }), // 其他 PostCSS 插件配置 ], }, }, })