From b619b35e9a3fc20e372e22fa7b10866a0ae7a320 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Tue, 22 Oct 2024 15:34:36 +0100 Subject: [PATCH] fix(webpack): only insert dynamic require plugin when building --- packages/webpack/src/webpack.ts | 34 +++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/packages/webpack/src/webpack.ts b/packages/webpack/src/webpack.ts index f1b178af54..96177faeb7 100644 --- a/packages/webpack/src/webpack.ts +++ b/packages/webpack/src/webpack.ts @@ -34,24 +34,26 @@ export const bundle: NuxtBuilder['bundle'] = async (nuxt) => { })) /** Inject rollup plugin for Nitro to handle dynamic imports from webpack chunks */ - const nitro = useNitro() - const dynamicRequirePlugin = dynamicRequire({ - dir: resolve(nuxt.options.buildDir, 'dist/server'), - inline: + if (!nuxt.options.dev) { + const nitro = useNitro() + const dynamicRequirePlugin = dynamicRequire({ + dir: resolve(nuxt.options.buildDir, 'dist/server'), + inline: nitro.options.node === false || nitro.options.inlineDynamicImports, - ignore: [ - 'client.manifest.mjs', - 'server.js', - 'server.cjs', - 'server.mjs', - 'server.manifest.mjs', - ], - }) - const prerenderRollupPlugins = nitro.options._config.rollupConfig!.plugins as InputPluginOption[] - const rollupPlugins = nitro.options.rollupConfig!.plugins as InputPluginOption[] + ignore: [ + 'client.manifest.mjs', + 'server.js', + 'server.cjs', + 'server.mjs', + 'server.manifest.mjs', + ], + }) + const prerenderRollupPlugins = nitro.options._config.rollupConfig!.plugins as InputPluginOption[] + const rollupPlugins = nitro.options.rollupConfig!.plugins as InputPluginOption[] - prerenderRollupPlugins.push(dynamicRequirePlugin) - rollupPlugins.push(dynamicRequirePlugin) + prerenderRollupPlugins.push(dynamicRequirePlugin) + rollupPlugins.push(dynamicRequirePlugin) + } await nuxt.callHook(`${builder}:config`, webpackConfigs)