85 lines
2.6 KiB
TypeScript
85 lines
2.6 KiB
TypeScript
import { defineConfig, loadEnv } from 'vite'
|
|
import vue from '@vitejs/plugin-vue'
|
|
import path from 'path'
|
|
import AutoImport from 'unplugin-auto-import/vite'
|
|
import Components from 'unplugin-vue-components/vite'
|
|
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
|
|
import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers'
|
|
|
|
export default defineConfig(({ mode }) => {
|
|
const env = loadEnv(mode, process.cwd(), '')
|
|
const proxyTarget = (env.VITE_DEV_PROXY_TARGET || 'http://127.0.0.1:80').trim()
|
|
const proxyToCoreDirectly = /(^|:)81(\/|$)/.test(proxyTarget)
|
|
const shouldWriteDeclarationFiles = mode === 'development'
|
|
|
|
return {
|
|
plugins: [
|
|
vue(),
|
|
AutoImport({
|
|
resolvers: [ElementPlusResolver()],
|
|
imports: ['vue', 'vue-router', 'pinia'],
|
|
dts: shouldWriteDeclarationFiles ? 'src/auto-import.d.ts' : false
|
|
}),
|
|
Components({
|
|
resolvers: [ElementPlusResolver(), AntDesignVueResolver({ importStyle: 'less' })],
|
|
dts: shouldWriteDeclarationFiles ? 'src/components.d.ts' : false
|
|
}),
|
|
{
|
|
name: 'ip-access-control',
|
|
configureServer(server) {
|
|
server.middlewares.use((_req, _res, next) => {
|
|
next()
|
|
})
|
|
}
|
|
}
|
|
],
|
|
resolve: {
|
|
alias: {
|
|
'@': path.resolve(__dirname, './src')
|
|
}
|
|
},
|
|
server: {
|
|
port: 3000,
|
|
host: '0.0.0.0',
|
|
proxy: {
|
|
'/admin/api': {
|
|
target: proxyTarget,
|
|
changeOrigin: true,
|
|
rewrite: path => proxyToCoreDirectly ? path.replace(/^\/admin\/api/, '/admin') : path
|
|
},
|
|
'/api': {
|
|
target: proxyTarget,
|
|
changeOrigin: true,
|
|
rewrite: path => proxyToCoreDirectly ? path.replace(/^\/api/, '') : path
|
|
}
|
|
},
|
|
allowedHosts: true
|
|
},
|
|
build: {
|
|
rollupOptions: {
|
|
output: {
|
|
manualChunks(id) {
|
|
if (!id.includes('node_modules')) {
|
|
return undefined
|
|
}
|
|
const normalizedId = id.replaceAll('\\', '/')
|
|
if (normalizedId.includes('@ant-design/icons-vue')) {
|
|
return 'antdv-icons'
|
|
}
|
|
if (normalizedId.includes('ant-design-vue')) {
|
|
return 'antdv'
|
|
}
|
|
if (normalizedId.includes('element-plus') || normalizedId.includes('@element-plus')) {
|
|
return 'element-plus'
|
|
}
|
|
if (normalizedId.includes('vue-router') || normalizedId.includes('pinia') || normalizedId.includes('/vue/')) {
|
|
return 'vue-core'
|
|
}
|
|
return 'vendor'
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
})
|