12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- 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: './', // 设置打包路径
- 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: {
- preprocessorOptions: {
- scss: {
- additionalData: '@import "./src/style/index.scss";' // 添加公共样式
- }
- },
- postcss: {
- plugins: [
- postCssPxToRem({
- rootValue: 37.5, // Vant 官方根字体大小是 37.5
- propList: ['*'],
- selectorBlackList: ['.norem'] // 过滤掉.norem-开头的class,不进行rem转换
- })
- ]
- }
- }
- })
|