micro-app/packages/icpx-platform/plugins/vitePluginDotFallback.ts
2023-05-30 19:27:03 +08:00

21 lines
556 B
TypeScript

/**
* Vite doesn't handle fallback html with dot (.), see https://github.com/vitejs/vite/issues/2415
* TODO: Review the PR in Vite
* @returns {import('vite').Plugin}
*/
export function spaFallbackWithDot() {
return {
name: 'spa-fallback-with-dot',
configureServer(server) {
return () => {
server.middlewares.use(function customSpaFallback(req, res, next) {
if (req.url.includes('.') && !req.url.endsWith('.html')) {
req.url = '/index.html';
}
next();
});
};
},
};
}