2022-02-20 22:42:48 +00:00
|
|
|
import vue from '@vitejs/plugin-vue'
|
|
|
|
import { resolve } from 'path'
|
2022-06-25 16:17:44 +00:00
|
|
|
import type { UserConfig, ConfigEnv, ProxyOptions } from 'vite'
|
2022-02-20 22:42:48 +00:00
|
|
|
import { isProd, loadEnv } from '/@/utils/vite'
|
|
|
|
import { svgBuilder } from '/@/components/icon/svg/index'
|
|
|
|
|
|
|
|
const pathResolve = (dir: string): any => {
|
|
|
|
return resolve(__dirname, '.', dir)
|
|
|
|
}
|
|
|
|
|
|
|
|
// https://vitejs.cn/config/
|
2022-02-24 17:44:00 +00:00
|
|
|
const viteConfig = ({ mode }: ConfigEnv): UserConfig => {
|
2022-06-25 16:17:44 +00:00
|
|
|
const { VITE_PORT, VITE_OPEN, VITE_BASE_PATH, VITE_OUT_DIR, VITE_PROXY_URL } = loadEnv(mode)
|
2022-02-24 17:44:00 +00:00
|
|
|
|
|
|
|
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',
|
|
|
|
}
|
|
|
|
|
2022-06-25 16:17:44 +00:00
|
|
|
let proxy: Record<string, string | ProxyOptions> = {}
|
|
|
|
if (VITE_PROXY_URL) {
|
|
|
|
proxy = {
|
2022-10-25 13:02:51 +00:00
|
|
|
'/': {
|
2022-06-25 16:17:44 +00:00
|
|
|
target: VITE_PROXY_URL,
|
|
|
|
changeOrigin: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-24 17:44:00 +00:00
|
|
|
return {
|
|
|
|
plugins: [vue(), svgBuilder('./src/assets/icons/')],
|
|
|
|
root: process.cwd(),
|
|
|
|
resolve: { alias },
|
|
|
|
base: VITE_BASE_PATH,
|
|
|
|
server: {
|
|
|
|
host: '0.0.0.0',
|
|
|
|
port: VITE_PORT,
|
|
|
|
open: VITE_OPEN,
|
2022-06-25 16:17:44 +00:00
|
|
|
proxy: proxy,
|
2022-02-24 17:44:00 +00:00
|
|
|
},
|
|
|
|
build: {
|
2022-10-25 11:11:13 +00:00
|
|
|
cssCodeSplit: false,
|
2022-02-24 17:44:00 +00:00
|
|
|
sourcemap: false,
|
|
|
|
outDir: VITE_OUT_DIR,
|
|
|
|
emptyOutDir: true,
|
|
|
|
chunkSizeWarningLimit: 1500,
|
2022-10-25 11:11:13 +00:00
|
|
|
rollupOptions: {
|
|
|
|
output: {
|
|
|
|
manualChunks: {
|
|
|
|
// 分包配置,配置完成自动按需加载
|
|
|
|
vue: ['vue', 'vue-router', 'pinia', 'vue-i18n', 'element-plus'],
|
|
|
|
echarts: ['echarts'],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-02-24 17:44:00 +00:00
|
|
|
},
|
|
|
|
}
|
2022-02-20 22:42:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default viteConfig
|