71 lines
2.0 KiB
TypeScript
71 lines
2.0 KiB
TypeScript
import { fileURLToPath, URL } from 'node:url'
|
|
import { defineConfig, loadEnv } from 'vite'
|
|
import vue from '@vitejs/plugin-vue'
|
|
import AutoImport from 'unplugin-auto-import/vite'
|
|
import Components from 'unplugin-vue-components/vite'
|
|
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
|
|
import { mockPlugin } from './mock/plugin'
|
|
|
|
export default defineConfig(({ mode }) => {
|
|
const env = loadEnv(mode, process.cwd(), '')
|
|
|
|
return {
|
|
base: env.VITE_APP_BASE_URL || '/',
|
|
plugins: [
|
|
vue(),
|
|
AutoImport({
|
|
imports: ['vue', 'vue-router', 'pinia', '@vueuse/core'],
|
|
resolvers: [ElementPlusResolver()],
|
|
dts: 'src/types/auto-imports.d.ts',
|
|
eslintrc: { enabled: true, filepath: './.eslintrc-auto-import.json' },
|
|
}),
|
|
Components({
|
|
resolvers: [ElementPlusResolver()],
|
|
dts: 'src/types/components.d.ts',
|
|
dirs: ['src/components'],
|
|
}),
|
|
mockPlugin(env.VITE_USE_MOCK === 'true'),
|
|
],
|
|
resolve: {
|
|
alias: {
|
|
'@': fileURLToPath(new URL('./src', import.meta.url)),
|
|
},
|
|
},
|
|
css: {
|
|
preprocessorOptions: {
|
|
scss: {
|
|
additionalData: `@use "@/styles/variables.scss" as *;`,
|
|
},
|
|
},
|
|
},
|
|
server: {
|
|
host: true,
|
|
port: Number(env.VITE_APP_PORT) || 3000,
|
|
open: true,
|
|
proxy: {
|
|
// 接口:请求以 /api/... 发起,直接转发到后端(后端以 /api 提供服务,无需重写路径)
|
|
'/api': {
|
|
target: env.VITE_APP_API_URL,
|
|
changeOrigin: true,
|
|
},
|
|
// 文件静态资源由后端 r.Static 提供,dev 下直连后端
|
|
'/files': {
|
|
target: env.VITE_APP_API_URL,
|
|
changeOrigin: true,
|
|
},
|
|
},
|
|
},
|
|
build: {
|
|
chunkSizeWarningLimit: 2000,
|
|
rollupOptions: {
|
|
output: {
|
|
manualChunks: {
|
|
vue: ['vue', 'vue-router', 'pinia'],
|
|
elementPlus: ['element-plus', '@element-plus/icons-vue'],
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
})
|