90 lines
2.5 KiB
TypeScript
90 lines
2.5 KiB
TypeScript
import { fileURLToPath, URL } from 'node:url'
|
|
|
|
import vue from '@vitejs/plugin-vue'
|
|
import vueJsx from '@vitejs/plugin-vue-jsx'
|
|
import _ from 'lodash'
|
|
import AutoImport from 'unplugin-auto-import/vite'
|
|
import IconsResolver from 'unplugin-icons/resolver'
|
|
import Icons from 'unplugin-icons/vite'
|
|
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
|
|
import Components from 'unplugin-vue-components/vite'
|
|
import { defineConfig, loadEnv } from 'vite'
|
|
|
|
// export function parseEnv(env: Record<string, any>): ImportMetaEnv {
|
|
export function parseEnv(env: Record<string, any>): any {
|
|
const envs: any = _.cloneDeep(env)
|
|
|
|
Object.entries(env).forEach(([key, value]) => {
|
|
if (value == 'true' || value == 'false') envs[key] = value == 'true' ? true : false
|
|
else if (/^\d+$/.test(value)) envs[key] = Number(value)
|
|
else if (value == 'null' || value == '') envs[key] = null
|
|
else if (value == 'undefined') envs[key] = undefined
|
|
})
|
|
return envs
|
|
}
|
|
// https://vitejs.dev/config/
|
|
export default defineConfig(({ command, mode }) => {
|
|
const isBuild = command == 'build'
|
|
const env = parseEnv(loadEnv(mode, process.cwd()))
|
|
return {
|
|
plugins: [
|
|
vue(),
|
|
vueJsx(),
|
|
|
|
AutoImport({
|
|
resolvers: [
|
|
ElementPlusResolver(),
|
|
IconsResolver({
|
|
prefix: 'Icon'
|
|
})
|
|
],
|
|
imports: ['vue', 'vue-router'],
|
|
//composables目录文件按需加载
|
|
dirs: ['src/composables/**/*', 'src/enum/**/*', 'src/store/**/*'],
|
|
dts: 'src/auto-import.d.ts', // 会自动生成此文件
|
|
vueTemplate: true,
|
|
defaultExportByFilename: true
|
|
}),
|
|
|
|
Components({
|
|
resolvers: [
|
|
// Auto register icon components
|
|
// 自动注册图标组件
|
|
IconsResolver({
|
|
enabledCollections: ['ep']
|
|
}),
|
|
ElementPlusResolver()
|
|
],
|
|
extensions: ['vue', 'tsx'],
|
|
dirs: ['src/components', 'src/layouts'],
|
|
//组件名称包含目录,防止同名组件冲突
|
|
directoryAsNamespace: true
|
|
}),
|
|
|
|
Icons({
|
|
autoInstall: true
|
|
})
|
|
],
|
|
resolve: {
|
|
alias: {
|
|
'@': fileURLToPath(new URL('./src', import.meta.url))
|
|
}
|
|
},
|
|
|
|
server: {
|
|
port: 8899,
|
|
host: true,
|
|
proxy: {
|
|
'/api': {
|
|
target: env.VITE_API_URL,
|
|
changeOrigin: true
|
|
},
|
|
'/captcha': {
|
|
target: env.VITE_API_URL,
|
|
changeOrigin: true
|
|
}
|
|
}
|
|
}
|
|
}
|
|
})
|