Repository: vercel/next.js
File: packages/next/src/build/webpack-config.ts (TypeScript)

Code before:
): Promise<webpack.Configuration> {
  const bundler = getWebpackBundler()
  const isClient = compilerType === COMPILER_NAMES.client
  const isEdgeServer = compilerType === COMPILER_NAMES.edgeServer
  const isNodeServer = compilerType === COMPILER_NAMES.server

  const isRspack = Boolean(process.env.NEXT_RSPACK)

  const FlightClientEntryPlugin =
    isRspack && process.env.BUILTIN_FLIGHT_CLIENT_ENTRY_PLUGIN
      ? RspackFlightClientEntryPlugin
      : NextFlightClientEntryPlugin

  // If the current compilation is aimed at server-side code instead of client-side code.
  const isNodeOrEdgeCompilation = isNodeServer || isEdgeServer

  const hasRewrites =
    rewrites.beforeFiles.length > 0 ||
    rewrites.afterFiles.length > 0 ||
    rewrites.fallback.length > 0

  const hasAppDir = !!appDir
  const disableOptimizedLoading = true
  const bundledReactChannel = needsExperimentalReact(config)
    ? '-experimental'
    : ''

  const babelConfigFile = getBabelConfigFile(dir)

  if (!dev && hasCustomExportOutput(config)) {
    config.distDir = '.next'
  }
  const distDir = path.join(dir, config.distDir)

  let useSWCLoader = !babelConfigFile || config.experimental.forceSwcTransforms
  let SWCBinaryTarget: [Feature, boolean] | undefined = undefined
  if (useSWCLoader) {
    // TODO: we do not collect wasm target yet
    const binaryTarget = (
      require('./swc') as typeof import('./swc')
    )?.getBinaryMetadata?.()?.target as SWC_TARGET_TRIPLE
    SWCBinaryTarget = binaryTarget
      ? [`swc/target/${binaryTarget}` as const, true]
      : undefined
  }

  if (!loggedSwcDisabled && !useSWCLoader && babelConfigFile) {
    Log.info(
      `Disabled SWC as replacement for Babel because of custom Babel configuration "${path.relative(
        dir,
        babelConfigFile

Review comment (suggestion):
`loadConfig` already merges `NextBuildContext.reactProductionProfiling` into `config. reactProductionProfiling` (if set)


Code after:
  const isClient = compilerType === COMPILER_NAMES.client
  const isEdgeServer = compilerType === COMPILER_NAMES.edgeServer
  const isNodeServer = compilerType === COMPILER_NAMES.server

  const isRspack = Boolean(process.env.NEXT_RSPACK)

  const FlightClientEntryPlugin =
    isRspack && process.env.BUILTIN_FLIGHT_CLIENT_ENTRY_PLUGIN
      ? RspackFlightClientEntryPlugin
      : NextFlightClientEntryPlugin

  // If the current compilation is aimed at server-side code instead of client-side code.
  const isNodeOrEdgeCompilation = isNodeServer || isEdgeServer

  const hasRewrites =
    rewrites.beforeFiles.length > 0 ||
    rewrites.afterFiles.length > 0 ||
    rewrites.fallback.length > 0

  const hasAppDir = !!appDir
  const disableOptimizedLoading = true
  const bundledReactChannel = needsExperimentalReact(config)
    ? '-experimental'
    : ''

  const reactProductionProfiling = config.reactProductionProfiling ?? false

  const babelConfigFile = getBabelConfigFile(dir)

  if (!dev && hasCustomExportOutput(config)) {
    config.distDir = '.next'
  }
  const distDir = path.join(dir, config.distDir)

  let useSWCLoader = !babelConfigFile || config.experimental.forceSwcTransforms
  let SWCBinaryTarget: [Feature, boolean] | undefined = undefined
  if (useSWCLoader) {
    // TODO: we do not collect wasm target yet
    const binaryTarget = (
      require('./swc') as typeof import('./swc')
    )?.getBinaryMetadata?.()?.target as SWC_TARGET_TRIPLE
    SWCBinaryTarget = binaryTarget
      ? [`swc/target/${binaryTarget}` as const, true]
      : undefined
  }

  if (!loggedSwcDisabled && !useSWCLoader && babelConfigFile) {
    Log.info(
      `Disabled SWC as replacement for Babel because of custom Babel configuration "${path.relative(
        dir,
        babelConfigFile