map/ui/dasadmin/vite.config.ts

94 lines
2.9 KiB
TypeScript
Raw Normal View History

2024-06-13 11:30:23 +08:00
import vue from '@vitejs/plugin-vue'
import { resolve } from 'path'
import { loadEnv } from 'vite'
import type { UserConfig, ConfigEnv, ProxyOptions } from 'vite'
import { isProd, customHotUpdate } from '/@/utils/vite'
import { svgBuilder } from '/@/components/icon/svg/index'
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_APP_PROXY } = loadEnv(mode, process.cwd())
const alias: Record<string, string> = {
'/@': pathResolve('./src/'),
assets: pathResolve('./src/assets'),
2024-06-20 13:56:06 +08:00
'vue-i18n': 'vue-i18n/dist/vue-i18n.cjs.js',
2024-06-13 11:30:23 +08:00
}
const createProxy = (proxyList: any) => {
const ret = {} as Record<string, ProxyOptions>
2024-06-19 16:32:11 +08:00
if (proxyList) {
proxyList = JSON.parse(proxyList)
for (const [prefix, target] of proxyList) {
ret[prefix] = {
target: target,
changeOrigin: true,
rewrite: (path) => path.replace(new RegExp(`^${prefix}`), ''),
}
2024-06-13 11:30:23 +08:00
}
}
return ret
}
// let proxy: Record<string, string | ProxyOptions> = {}
// if (VITE_PROXY_URL) {
// proxy = {
// '/': {
// target: VITE_PROXY_URL,
// changeOrigin: true,
// },
// }
// }
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',
proxy: {
2024-06-19 16:32:11 +08:00
...createProxy(VITE_APP_PROXY),
2024-06-13 11:30:23 +08:00
},
},
2024-11-01 12:45:46 +08:00
esbuild: {
drop: ['console', 'debugger'],
},
2024-06-13 11:30:23 +08:00
build: {
cssCodeSplit: false,
sourcemap: false,
outDir: VITE_OUT_DIR,
emptyOutDir: true,
chunkSizeWarningLimit: 1500,
2024-11-01 12:45:46 +08:00
// terserOptions: {
// compress: {
// keep_infinity: true,
// // Used to delete console in production environment
// drop_console: true,
// drop_debugger: true,
// },
// output: {
// comments: true, // 去掉注释内容
// },
// },
2024-06-13 11:30:23 +08:00
rollupOptions: {
output: {
manualChunks: {
// 分包配置,配置完成自动按需加载
vue: ['vue', 'vue-router', 'pinia', 'vue-i18n', 'element-plus'],
echarts: ['echarts'],
},
},
},
},
}
}
export default viteConfig