Files
webman-buildadmin-mall/web/vite.config.ts
2026-03-18 19:21:10 +08:00

57 lines
2.1 KiB
TypeScript
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 vue from '@vitejs/plugin-vue'
import { resolve } from 'path'
import type { ConfigEnv, UserConfig } from 'vite'
import { loadEnv } from 'vite'
import { svgBuilder } from '/@/components/icon/svg/index'
import { customHotUpdate, isProd } from '/@/utils/vite'
const pathResolve = (dir: string): any => {
return resolve(__dirname, '.', dir)
}
// https://vitejs.cn/config/
const viteConfig = ({ mode }: ConfigEnv): UserConfig => {
const { VITE_PORT, VITE_OPEN, VITE_BASE_PATH, VITE_OUT_DIR, VITE_PROXY_TARGET } = loadEnv(mode, process.cwd())
const alias: Record<string, string> = {
'/@': pathResolve('./src/'),
assets: pathResolve('./src/assets'),
'vue-i18n': isProd(mode) ? 'vue-i18n/dist/vue-i18n.cjs.prod.js' : 'vue-i18n/dist/vue-i18n.cjs.js',
}
return {
plugins: [vue(), svgBuilder('./src/assets/icons/'), customHotUpdate()],
root: process.cwd(),
resolve: { alias },
base: VITE_BASE_PATH,
server: {
port: parseInt(VITE_PORT),
open: VITE_OPEN != 'false',
// 开发时把 /api、/admin、/install 代理到 webman避免跨域
proxy: {
'/api': { target: VITE_PROXY_TARGET || 'http://localhost:6969', changeOrigin: true },
'/admin': { target: VITE_PROXY_TARGET || 'http://localhost:6969', changeOrigin: true },
'/install': { target: VITE_PROXY_TARGET || 'http://localhost:6969', changeOrigin: true },
},
},
build: {
cssCodeSplit: false,
sourcemap: false,
outDir: VITE_OUT_DIR,
emptyOutDir: true,
chunkSizeWarningLimit: 1500,
rollupOptions: {
output: {
manualChunks: {
// 分包配置,配置完成自动按需加载
vue: ['vue', 'vue-router', 'pinia', 'vue-i18n', 'element-plus'],
echarts: ['echarts'],
},
},
},
},
}
}
export default viteConfig