feat(build): allow using `transformIndexHtml` (#1380)

pull/1385/head
Divyansh Singh 2 years ago committed by GitHub
parent b330ebb598
commit ce8d139a8e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -35,6 +35,9 @@ const isPageChunk = (
chunk.facadeModuleId.endsWith('.md')
)
const cleanUrl = (url: string): string =>
url.replace(/#.*$/s, '').replace(/\?.*$/s, '')
export async function createVitePressPlugin(
siteConfig: SiteConfig,
ssr = false,
@ -176,12 +179,12 @@ export async function createVitePressPlugin(
// serve our index.html after vite history fallback
return () => {
server.middlewares.use((req, res, next) => {
if (req.url!.replace(/\?.*$/, '').endsWith('.html')) {
server.middlewares.use(async (req, res, next) => {
const url = req.url && cleanUrl(req.url)
if (url?.endsWith('.html')) {
res.statusCode = 200
res.setHeader('Content-Type', 'text/html')
res.end(`
<!DOCTYPE html>
let html = `<!DOCTYPE html>
<html>
<head>
<title></title>
@ -193,7 +196,9 @@ export async function createVitePressPlugin(
<div id="app"></div>
<script type="module" src="/@fs/${APP_PATH}/index.js"></script>
</body>
</html>`)
</html>`
html = await server.transformIndexHtml(url, html, req.originalUrl)
res.end(html)
return
}
next()

Loading…
Cancel
Save