fix(nuxt): access server build from webpack memfs (#29027)

This commit is contained in:
Daniel Roe 2024-09-16 22:44:39 +02:00 committed by GitHub
parent 68451570df
commit 27a7ca3c1e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -545,6 +545,12 @@ export async function initNitro (nuxt: Nuxt & { _nitro?: Nitro }) {
// nuxt dev
if (nuxt.options.dev) {
nuxt.hook('webpack:compile', ({ name, compiler }) => {
if (name === 'server') {
const memfs = compiler.outputFileSystem as typeof import('node:fs')
nitro.options.virtual['#build/dist/server/server.mjs'] = () => memfs.readFileSync(join(nuxt.options.buildDir, 'dist/server/server.mjs'), 'utf-8')
}
})
nuxt.hook('webpack:compiled', () => { nuxt.server.reload() })
nuxt.hook('vite:compiled', () => { nuxt.server.reload() })