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

This commit is contained in:
Daniel Roe 2024-09-16 22:44:39 +02:00
parent 0bf748597f
commit 3e5b307e42
No known key found for this signature in database
GPG Key ID: CBC814C393D93268

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() })