Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: apply post hooks after serving .html files #14859

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions packages/vite/src/node/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ export async function preview(

app.use(previewBase, viteAssetMiddleware)

// html fallback
if (config.appType === 'spa' || config.appType === 'mpa') {
// html fallback
app.use(
previewBase,
htmlFallbackMiddleware(
Expand All @@ -202,15 +202,14 @@ export async function preview(
previewBase !== '/',
),
)
// transform index.html
app.use(previewBase, indexHtmlMiddleware(distDir, server))
}

// apply post server hooks from plugins
postHooks.forEach((fn) => fn && fn())

if (config.appType === 'spa' || config.appType === 'mpa') {
// transform index.html
app.use(previewBase, indexHtmlMiddleware(distDir, server))

// handle 404s
app.use(previewBase, notFoundMiddleware())
}
Expand Down
7 changes: 3 additions & 4 deletions packages/vite/src/node/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -712,9 +712,11 @@ export async function _createServer(
middlewares.use(serveRawFsMiddleware(server))
middlewares.use(serveStaticMiddleware(root, server))

// html fallback
if (config.appType === 'spa' || config.appType === 'mpa') {
// html fallback
middlewares.use(htmlFallbackMiddleware(root, config.appType === 'spa'))
// transform index.html
middlewares.use(indexHtmlMiddleware(root, server))
}

// run post config hooks
Expand All @@ -723,9 +725,6 @@ export async function _createServer(
postHooks.forEach((fn) => fn && fn())

if (config.appType === 'spa' || config.appType === 'mpa') {
// transform index.html
middlewares.use(indexHtmlMiddleware(root, server))

// handle 404s
middlewares.use(notFoundMiddleware())
}
Expand Down