62 lines
1.8 KiB
TypeScript
62 lines
1.8 KiB
TypeScript
import process from 'node:process'
|
|
import { fileURLToPath, URL } from 'node:url'
|
|
import vue from '@vitejs/plugin-vue'
|
|
import IconsResolver from 'unplugin-icons/resolver'
|
|
import Icons from 'unplugin-icons/vite'
|
|
import Components from 'unplugin-vue-components/vite'
|
|
import { defineConfig, loadEnv } from 'vite'
|
|
|
|
export default defineConfig((configEnv) => {
|
|
const viteEnv = loadEnv(configEnv.mode, process.cwd()) as unknown as Env.ImportMeta
|
|
const { VITE_SERVER_BASEURL, VITE_APP_PROXY, VITE_APP_PROXY_PREFIX } = viteEnv
|
|
|
|
return {
|
|
base: viteEnv.VITE_BASE_URL,
|
|
resolve: {
|
|
// 使其通过能 ~ 或 @ 导入
|
|
alias: {
|
|
'~': fileURLToPath(new URL('./', import.meta.url)),
|
|
'@': fileURLToPath(new URL('./src', import.meta.url)),
|
|
},
|
|
},
|
|
css: {
|
|
preprocessorOptions: {
|
|
scss: {
|
|
api: 'modern-compiler',
|
|
additionalData: `@use "@/styles/scss/global.scss" as *;`,
|
|
},
|
|
},
|
|
},
|
|
plugins: [
|
|
vue(),
|
|
Icons(),
|
|
Components({
|
|
dts: 'src/types/auto-import.d.ts',
|
|
resolvers: [IconsResolver()],
|
|
}),
|
|
],
|
|
server: {
|
|
host: '0.0.0.0',
|
|
port: 8080,
|
|
open: true,
|
|
// 用于配置开发服务器启动时预加载的一些客户端文件,以提高初次加载的速度。
|
|
warmup: {
|
|
clientFiles: ['./index.html', './src/{pages,components}/*'],
|
|
},
|
|
proxy:
|
|
VITE_APP_PROXY === 'Y'
|
|
? {
|
|
[VITE_APP_PROXY_PREFIX]: {
|
|
target: VITE_SERVER_BASEURL,
|
|
changeOrigin: true, // 跨域
|
|
rewrite: path => path.replace(new RegExp(`^${VITE_APP_PROXY_PREFIX}`), ''),
|
|
},
|
|
}
|
|
: undefined,
|
|
},
|
|
preview: {
|
|
port: 9725,
|
|
},
|
|
}
|
|
})
|