优化开发服务器配置,新增根路径重定向至web首页,

This commit is contained in:
WUSIJIAN
2025-12-25 17:01:36 +08:00
parent 0a5b444dad
commit 73373ad7a1
5 changed files with 530 additions and 3 deletions

View File

@@ -17,7 +17,24 @@ const alias: Record<string, string> = {
const viteConfig = defineConfig((mode: ConfigEnv) => {
const env = loadEnv(mode.mode, process.cwd());
return {
plugins: [vue(), viteCompression({ disable: true })],
plugins: [
vue(),
viteCompression({ disable: true }),
// 根路径重定向到 web 首页
{
name: 'redirect-root-to-web',
configureServer(server) {
server.middlewares.use((req, res, next) => {
if (req.url === '/' || req.url === '') {
res.writeHead(302, { Location: '/web/index.html' });
res.end();
return;
}
next();
});
},
},
],
root: process.cwd(),
resolve: { alias },
base: mode.command === 'serve' ? './' : env.VITE_PUBLIC_PATH,
@@ -25,7 +42,7 @@ const viteConfig = defineConfig((mode: ConfigEnv) => {
server: {
host: '0.0.0.0',
port: env.VITE_PORT as unknown as number,
open: JSON.parse(env.VITE_OPEN),
open: false,
hmr: true,
// proxy: {
// '/gitee': {