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

Loading…
Cancel
Save