Files
Jnote-nodeJs/vite.config.js
dcr_xuxgc d759a9e740 init
2026-06-12 17:49:54 +08:00

36 lines
1018 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { fileURLToPath } from 'url'
import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
// Vite 配置
export default defineConfig(({ mode }) => {
// 加载环境变量
const env = loadEnv(mode, process.cwd(), '')
return {
plugins: [vue()],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
}
},
server: {
port: 5173,
proxy: {
'/api': {
// 本地开发模式VITE_SERVER_URL 为空或本地地址时使用代理
target: env.VITE_SERVER_URL || `http://localhost:${env.VITE_API_PORT || '3000'}`,
changeOrigin: true,
// 仅远程部署时改变 origin
configure: (proxy) => {
if (env.VITE_SERVER_URL && !env.VITE_SERVER_URL.includes('localhost')) {
proxy.on('proxyReq', (proxyReq) => {
proxyReq.setHeader('origin', env.VITE_SERVER_URL)
})
}
}
}
}
}
}
})