Repository: nuxt/nuxt
File: packages/webpack/src/webpack.ts (TypeScript)

Code before:
import { ChunkErrorPlugin } from './plugins/chunk'
import { createMFS } from './utils/mfs'
import { client, server } from './configs'
import { applyPresets, createWebpackConfigContext } from './utils/config'
import { dynamicRequire } from './nitro/plugins/dynamic-require'

import { builder, webpack } from '#builder'

// TODO: Support plugins
// const plugins: string[] = []

export const bundle: NuxtBuilder['bundle'] = async (nuxt) => {
  const webpackConfigs = await Promise.all([client, ...nuxt.options.ssr ? [server] : []].map(async (preset) => {
    const ctx = createWebpackConfigContext(nuxt)
    ctx.userConfig = defu(nuxt.options.webpack[`$${preset.name as 'client' | 'server'}`], ctx.userConfig)
    await applyPresets(ctx, preset)
    return ctx.config
  }))

  /** Inject rollup plugin for Nitro to handle dynamic imports from webpack chunks */
  if (!nuxt.options.dev) {
    const nitro = useNitro()
    nitro.hooks.hook('rollup:before', (nitro, config) => {
      const rollupCompatPlugin = dynamicRequire({
        dir: resolve(nuxt.options.buildDir, 'dist/server'),
      })
      const plugins = config.plugins as InputPluginOption[]

      const existingPlugin = plugins.findIndex(i => i && 'name' in i && i.name === 'dynamic-require')
      if (existingPlugin >= 0) {
        plugins.splice(existingPlugin, 1, rollupCompatPlugin)
      } else {
        plugins.push(rollupCompatPlugin)
      }
    })
  }

  await nuxt.callHook(`${builder}:config`, webpackConfigs)

  // Initialize shared MFS for dev
  const mfs = nuxt.options.dev ? createMFS() : null

  for (const config of webpackConfigs) {
    config.plugins!.push(DynamicBasePlugin.webpack({
      sourcemap: !!nuxt.options.sourcemap[config.name as 'client' | 'server'],
    }))
    // Emit chunk errors if the user has opted in to `experimental.emitRouteChunkError`
    if (config.name === 'client' && nuxt.options.experimental.emitRouteChunkError && nuxt.options.builder !== '@nuxt/rspack-builder') {
      config.plugins!.push(new ChunkErrorPlugin())
    }
  }

Review comment (suggestion):
```suggestion
      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',
	      ],
	    })
```

Code after:
import { createMFS } from './utils/mfs'
import { client, server } from './configs'
import { applyPresets, createWebpackConfigContext } from './utils/config'

import { builder, webpack } from '#builder'

// TODO: Support plugins
// const plugins: string[] = []

export const bundle: NuxtBuilder['bundle'] = async (nuxt) => {
  const webpackConfigs = await Promise.all([client, ...nuxt.options.ssr ? [server] : []].map(async (preset) => {
    const ctx = createWebpackConfigContext(nuxt)
    ctx.userConfig = defu(nuxt.options.webpack[`$${preset.name as 'client' | 'server'}`], ctx.userConfig)
    await applyPresets(ctx, preset)
    return ctx.config
  }))

  /** Remove Nitro rollup plugin for handling dynamic imports from webpack chunks */
  if (!nuxt.options.dev) {
    const nitro = useNitro()
    nitro.hooks.hook('rollup:before', (_nitro, config) => {
      const plugins = config.plugins as InputPluginOption[]

      const existingPlugin = plugins.findIndex(i => i && 'name' in i && i.name === 'dynamic-require')
      if (existingPlugin >= 0) {
        plugins.splice(existingPlugin, 1)
      }
    })
  }

  await nuxt.callHook(`${builder}:config`, webpackConfigs)

  // Initialize shared MFS for dev
  const mfs = nuxt.options.dev ? createMFS() : null

  for (const config of webpackConfigs) {
    config.plugins!.push(DynamicBasePlugin.webpack({
      sourcemap: !!nuxt.options.sourcemap[config.name as 'client' | 'server'],
    }))
    // Emit chunk errors if the user has opted in to `experimental.emitRouteChunkError`
    if (config.name === 'client' && nuxt.options.experimental.emitRouteChunkError && nuxt.options.builder !== '@nuxt/rspack-builder') {
      config.plugins!.push(new ChunkErrorPlugin())
    }
  }

  await nuxt.callHook(`${builder}:configResolved`, webpackConfigs)

  // Configure compilers
  const compilers = webpackConfigs.map((config) => {
    // Create compiler
    const compiler = webpack(config)