完善项目
This commit is contained in:
@@ -7,8 +7,22 @@ export default defineConfig(({ mode }) => {
|
||||
// 加载环境变量
|
||||
const env = loadEnv(mode, process.cwd(), '')
|
||||
|
||||
// 自定义重定向插件
|
||||
const redirectPlugin = () => {
|
||||
return {
|
||||
name: 'redirect-plugin',
|
||||
configureServer(server) {
|
||||
server.middlewares.use('/login', (req, res, next) => {
|
||||
res.writeHead(302, { Location: '/farm/login' })
|
||||
res.end()
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
plugins: [vue()],
|
||||
base: '/farm/',
|
||||
plugins: [vue(), redirectPlugin()],
|
||||
resolve: {
|
||||
alias: {
|
||||
'@': resolve(__dirname, 'src')
|
||||
@@ -23,6 +37,11 @@ export default defineConfig(({ mode }) => {
|
||||
changeOrigin: true,
|
||||
rewrite: (path) => path.replace(/^\/api/, '/api')
|
||||
}
|
||||
},
|
||||
// 开发环境重定向配置
|
||||
middlewareMode: false,
|
||||
fs: {
|
||||
strict: false
|
||||
}
|
||||
},
|
||||
build: {
|
||||
@@ -38,7 +57,11 @@ export default defineConfig(({ mode }) => {
|
||||
},
|
||||
define: {
|
||||
// 将环境变量注入到应用中
|
||||
__APP_ENV__: JSON.stringify(env)
|
||||
__APP_ENV__: JSON.stringify(env),
|
||||
// 在生产环境中强制使用正确的API URL
|
||||
'import.meta.env.VITE_API_BASE_URL': JSON.stringify(
|
||||
mode === 'production' ? 'https://ad.ningmuyun.com/farm/api' : (env.VITE_API_BASE_URL || '/api')
|
||||
)
|
||||
}
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user