You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
1.3 KiB
41 lines
1.3 KiB
import { fileURLToPath, URL } from 'node:url'
|
|
import { defineConfig } from 'vite'
|
|
import vue from '@vitejs/plugin-vue'
|
|
import AutoImport from 'unplugin-auto-import/vite'
|
|
import Components from 'unplugin-vue-components/vite'
|
|
import { TDesignResolver } from 'unplugin-vue-components/resolvers'
|
|
import { HttpProxyAgent } from 'http-proxy-agent'
|
|
|
|
// 本机若配置了 http_proxy(如 7890),Vite 代理出站需显式走 agent,否则直连局域网可能 EHOSTUNREACH
|
|
const outboundProxy = process.env.http_proxy || process.env.HTTP_PROXY || ''
|
|
const proxyAgent = outboundProxy ? new HttpProxyAgent(outboundProxy) : undefined
|
|
|
|
export default defineConfig({
|
|
plugins: [
|
|
vue(),
|
|
AutoImport({
|
|
resolvers: [TDesignResolver({ library: 'vue-next' })],
|
|
}),
|
|
Components({
|
|
resolvers: [TDesignResolver({ library: 'vue-next' })],
|
|
}),
|
|
],
|
|
resolve: {
|
|
alias: {
|
|
'@': fileURLToPath(new URL('./src', import.meta.url)),
|
|
},
|
|
},
|
|
envPrefix: ['APP_', 'VITE_'],
|
|
server: {
|
|
host: '0.0.0.0',
|
|
port: 5173,
|
|
proxy: {
|
|
// 浏览器请求 /api/* → http://119.3.111.201/api/*(远程网关保留 /api 前缀)
|
|
'/api': {
|
|
target: 'http://119.3.111.201',
|
|
changeOrigin: true,
|
|
agent: proxyAgent,
|
|
},
|
|
},
|
|
},
|
|
})
|
|
|