fix(webpack): only insert dynamic require plugin when building

This commit is contained in:
Daniel Roe 2024-10-22 15:34:36 +01:00
parent 3fe427e620
commit b619b35e9a
No known key found for this signature in database
GPG Key ID: 3714AB03996F442B

View File

@ -34,24 +34,26 @@ export const bundle: NuxtBuilder['bundle'] = async (nuxt) => {
})) }))
/** Inject rollup plugin for Nitro to handle dynamic imports from webpack chunks */ /** Inject rollup plugin for Nitro to handle dynamic imports from webpack chunks */
const nitro = useNitro() if (!nuxt.options.dev) {
const dynamicRequirePlugin = dynamicRequire({ const nitro = useNitro()
dir: resolve(nuxt.options.buildDir, 'dist/server'), const dynamicRequirePlugin = dynamicRequire({
inline: dir: resolve(nuxt.options.buildDir, 'dist/server'),
inline:
nitro.options.node === false || nitro.options.inlineDynamicImports, nitro.options.node === false || nitro.options.inlineDynamicImports,
ignore: [ ignore: [
'client.manifest.mjs', 'client.manifest.mjs',
'server.js', 'server.js',
'server.cjs', 'server.cjs',
'server.mjs', 'server.mjs',
'server.manifest.mjs', 'server.manifest.mjs',
], ],
}) })
const prerenderRollupPlugins = nitro.options._config.rollupConfig!.plugins as InputPluginOption[] const prerenderRollupPlugins = nitro.options._config.rollupConfig!.plugins as InputPluginOption[]
const rollupPlugins = nitro.options.rollupConfig!.plugins as InputPluginOption[] const rollupPlugins = nitro.options.rollupConfig!.plugins as InputPluginOption[]
prerenderRollupPlugins.push(dynamicRequirePlugin) prerenderRollupPlugins.push(dynamicRequirePlugin)
rollupPlugins.push(dynamicRequirePlugin) rollupPlugins.push(dynamicRequirePlugin)
}
await nuxt.callHook(`${builder}:config`, webpackConfigs) await nuxt.callHook(`${builder}:config`, webpackConfigs)