vite.config.js文件配置
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import path from 'path'
import postcsspxtoviewport8plugin from 'postcss-px-to-viewport-8-plugin';
const resolve = str => path.resolve(__dirname, str)
export default defineConfig(({ mode }) => {
const ENV = loadEnv(mode, __dirname)
const IS_DEV = ENV.VITE_APP_ENV !== 'production'
return {
base: './',
resolve: {
alias: {
'@': resolve('src'),
'@components': resolve('src/components'),
'@utils': resolve('src/utils'),
'@views': resolve('src/views'),
'@assets': resolve('src/assets')
},
extensions: ['.js', '.ts', '.jsx', '.tsx', '.json', '.vue']
},
build: {
publicPath: './',
outDir: 'dist',
assetsDir: 'static',
sourcemap: IS_DEV,
chunkSizeWarningLimit: 700,
minify: 'terser',
terserOptions: {
compress: {
drop_console: !IS_DEV,
drop_debugger: !IS_DEV
}
},
rollupOptions: {
output: {
manualChunks: {
vlib: ['vue', 'vue-router', 'vuex']
}
}
}
},
server: {
port: 8088,
open: true,
proxy: {
'/api': 'http://127.0.0.1:3000'
},
cors: true
},
css: {
postcss: {
plugins: [
postcsspxtoviewport8plugin({
unitToConvert: 'px',
viewportWidth: 1920,
unitPrecision: 6,
propList: [
'*'
],
viewportUnit: 'vw',
fontViewportUnit: 'vw',
selectorBlackList: ['el-switch', 'is-checked'],
minPixelValue: 1,
mediaQuery: false,
replace: true,
exclude: /(\/|\\)(node_modules)(\/|\\)/
}),
{
postcssPlugin: 'internal:charset-removal',
AtRule: {
charset: atRule => {
if (atRule.name === 'charset') {
atRule.remove()
}
}
}
}
]
}
},
plugins: [
react()
],
}
})