import { defineConfig } from 'vite' import vue from '@vitejs/plugin-vue' import styleImport, { VantResolve } from 'vite-plugin-style-import' import postCssPxToRem from 'postcss-pxtorem' import WindiCSS from 'vite-plugin-windicss' import * as path from 'path' // https://vitejs.dev/config/ export default defineConfig({ server: { port: 4500, // 设置服务启动端口号 open: true, // 设置服务启动时是否自动打开浏览器 cors: true // 允许跨域 // 设置代理,根据我们项目实际情况配置 // proxy: { // '/api': { // target: 'http://xxx.xxx.xxx.xxx:x000', // changeOrigin: true, // secure: false, // rewrite: (path) => path.replace('/api/', '/') // } // }, }, base: './', // 设置打包路径 build:{ outDir: 'newMobile', }, plugins: [ vue(), WindiCSS(), styleImport({ // resolves: [VantResolve()], libs: [ { libraryName: 'vant', esModule: true, resolveStyle: component => `vant/es/${component}/style/index` } ] }) ], resolve: { alias: { '@': path.resolve(__dirname, 'src'), //使用@来代表src目录 components: path.resolve(__dirname, 'src/components'), styles: path.resolve(__dirname, 'src/styles'), plugins: path.resolve(__dirname, 'src/plugins'), views: path.resolve(__dirname, 'src/views'), layouts: path.resolve(__dirname, 'src/layouts'), utils: path.resolve(__dirname, 'src/utils'), apis: path.resolve(__dirname, 'src/apis'), dirs: path.resolve(__dirname, 'src/directives') } }, css: { postcss: { plugins: [ postCssPxToRem({ rootValue: 37.5, // Vant 官方根字体大小是 37.5 propList: ['*'], selectorBlackList: ['.norem'] // 过滤掉.norem-开头的class,不进行rem转换 }) ] } } })