Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

Commit

Permalink
feat(vite): support Vite's transformIndexHtml hook
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Nov 5, 2021
1 parent f461591 commit dd65101
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/bridge/src/vite/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ export async function buildClient (ctx: ViteBuildContext) {

// Create development server
const viteServer = await vite.createServer(clientConfig)

// Support Vite's transformIndexHtml hook
ctx.nuxt.hook('nitro:document', async (doc) => {
doc.contents = await viteServer.transformIndexHtml(doc.src, doc.contents) || doc.contents
})

await ctx.nuxt.callHook('vite:serverCreated', viteServer)

const viteMiddleware = (req, res, next) => {
Expand Down
6 changes: 6 additions & 0 deletions packages/vite/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ export async function buildClient (ctx: ViteBuildContext) {
await ctx.nuxt.callHook('vite:extendConfig', clientConfig, { isClient: true, isServer: false })

const viteServer = await vite.createServer(clientConfig)

// Support Vite's transformIndexHtml hook
ctx.nuxt.hook('nitro:document', async (doc) => {
doc.contents = await viteServer.transformIndexHtml(doc.src, doc.contents) || doc.contents
})

await ctx.nuxt.callHook('vite:serverCreated', viteServer)

const viteMiddleware: Connect.NextHandleFunction = (req, res, next) => {
Expand Down

0 comments on commit dd65101

Please sign in to comment.