Skip to content

Commit

Permalink
feat(build): allow using transformIndexHtml (vuejs#1380)
Browse files Browse the repository at this point in the history
  • Loading branch information
brc-dd authored Sep 21, 2022
1 parent b330ebb commit ce8d139
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/node/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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>
Expand All @@ -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()
Expand Down

0 comments on commit ce8d139

Please sign in to comment.