优化开发服务器配置,新增根路径重定向至web首页,
This commit is contained in:
@@ -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': {
|
||||
|
||||
Reference in New Issue
Block a user