Files
portal/vite.config.js
2025-09-03 18:05:48 +08:00

60 lines
1.5 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import {defineConfig} from 'vite'
import vue from '@vitejs/plugin-vue'
// 导入 path
import path from 'path'
// pxToRem
import postCssPxToRem from 'postcss-pxtorem'
// svg
import {createSvgIconsPlugin} from 'vite-plugin-svg-icons'
export default defineConfig({
base: './',
build: {
outDir: 'protal_dist',
// 打包时使用 terser 压缩代码
// minify: 'terser',
// 是否生成源映射文件,方便调试生产环境代码
sourcemap: 'inline',
},
plugins: [
vue(),
createSvgIconsPlugin({
// 指定 SVG 图标目录(绝对路径)
iconDirs: [path.resolve(process.cwd(), 'src/assets/icons/svg')],
// 指定 symbolId 格式
symbolId: 'icon-[dir]-[name]',
// 自定义插入位置(可选)
inject: 'body-last',
}),
],
resolve: {
// 配置别名
alias: {
'@': path.resolve(__dirname, './src'),
_c: path.resolve(__dirname, './src/components'),
},
// 省略扩展名导入
extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue'],
},
css: {
// scss 全局变量的配置
preprocessorOptions: {
scss: {
additionalData: `@use "@/assets/styles/variable.scss" as *;`,
api: 'modern-compiler',
silenceDeprecations: ['legacy-js-api'],
},
},
// pxToRem
postcss: {
plugins: [
postCssPxToRem({
// 1rem = 16px
rootValue: 16,
propList: ['*'], // 如果想要某些不适用rem使用!名字即可
}),
],
},
},
})