initial commit
This commit is contained in:
44
vite.config.ts
Normal file
44
vite.config.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import { fileURLToPath, URL } from 'node:url'
|
||||
|
||||
import { defineConfig, ProxyOptions } from 'vite'
|
||||
import vue from '@vitejs/plugin-vue'
|
||||
import vueJsx from '@vitejs/plugin-vue-jsx'
|
||||
import vueDevTools from 'vite-plugin-vue-devtools'
|
||||
|
||||
const apiProxyList: [string, string][] = [
|
||||
// ['/api', 'http://172.16.6.248:18760/api'],
|
||||
['/api', 'http://localhost:3000/api'],
|
||||
['/10/api', 'http://localhost:3000/api'],
|
||||
['/11/api', 'http://localhost:3000/api'],
|
||||
]
|
||||
|
||||
// https://vite.dev/config/
|
||||
export default defineConfig((/* { command, mode } */) => {
|
||||
const viteProxy: Record<string, string | ProxyOptions> = {}
|
||||
apiProxyList.forEach((apiProxy) => {
|
||||
const [prefix, target] = apiProxy
|
||||
viteProxy[prefix] = {
|
||||
target,
|
||||
changeOrigin: true,
|
||||
rewrite: (path) => {
|
||||
console.log(`请求路径: ${path}`)
|
||||
const rewrittenPath = path.replace(new RegExp(`^${prefix}`), '')
|
||||
console.log(`将代理到: ${target}${rewrittenPath}`)
|
||||
return rewrittenPath
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
return {
|
||||
plugins: [vue(), vueJsx(), vueDevTools()],
|
||||
resolve: {
|
||||
alias: {
|
||||
'@': fileURLToPath(new URL('./src', import.meta.url)),
|
||||
},
|
||||
},
|
||||
server: {
|
||||
port: 9654,
|
||||
proxy: viteProxy,
|
||||
},
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user