{"version":3,"sources":["../../../../../../src/build/webpack/config/blocks/base.ts"],"sourcesContent":["import curry from 'next/dist/compiled/lodash.curry'\nimport type { webpack } from 'next/dist/compiled/webpack/webpack'\nimport { COMPILER_NAMES } from '../../../../shared/lib/constants'\nimport type { ConfigurationContext } from '../utils'\nimport DevToolsIgnorePlugin from '../../plugins/devtools-ignore-list-plugin'\nimport EvalSourceMapDevToolPlugin from '../../plugins/eval-source-map-dev-tool-plugin'\nimport { getRspackCore } from '../../../../shared/lib/get-rspack'\n\nfunction shouldIgnorePath(modulePath: string): boolean {\n  return (\n    modulePath.includes('node_modules') ||\n    modulePath.endsWith('__nextjs-internal-proxy.cjs') ||\n    modulePath.endsWith('__nextjs-internal-proxy.mjs') ||\n    // Only relevant for when Next.js is symlinked e.g. in the Next.js monorepo\n    modulePath.includes('next/dist')\n  )\n}\n\nexport const base = curry(function base(\n  ctx: ConfigurationContext,\n  config: webpack.Configuration\n) {\n  config.mode = ctx.isDevelopment ? 'development' : 'production'\n  config.name = ctx.isServer\n    ? ctx.isEdgeRuntime\n      ? COMPILER_NAMES.edgeServer\n      : COMPILER_NAMES.server\n    : COMPILER_NAMES.client\n\n  config.target = !ctx.targetWeb\n    ? 'node18.17' // Same version defined in packages/next/package.json#engines\n    : ctx.isEdgeRuntime\n      ? ['web', 'es6']\n      : ['web', 'es6']\n\n  // https://webpack.js.org/configuration/devtool/#development\n  if (ctx.isDevelopment) {\n    // `eval-source-map` provides full-fidelity source maps for the\n    // original source, including columns and original variable names.\n    // This is desirable so the in-browser debugger can correctly pause\n    // and show scoped variables with their original names.\n    config.devtool = 'eval-source-map'\n  } else {\n    if (\n      ctx.isEdgeRuntime ||\n      (ctx.isServer && ctx.serverSourceMaps) ||\n      // Enable browser sourcemaps:\n      (ctx.productionBrowserSourceMaps && ctx.isClient)\n    ) {\n      config.devtool = 'source-map'\n    } else {\n      config.devtool = false\n    }\n  }\n\n  if (!config.module) {\n    config.module = { rules: [] }\n  }\n\n  config.plugins ??= []\n  if (config.devtool === 'source-map' && !process.env.NEXT_RSPACK) {\n    config.plugins.push(\n      new DevToolsIgnorePlugin({\n        shouldIgnorePath,\n      })\n    )\n  } else if (config.devtool === 'eval-source-map') {\n    // We're using a fork of `eval-source-map`\n    config.devtool = false\n    if (process.env.NEXT_RSPACK) {\n      config.plugins.push(\n        new (getRspackCore().EvalSourceMapDevToolPlugin)({\n          moduleFilenameTemplate: config.output?.devtoolModuleFilenameTemplate,\n        })\n      )\n    } else {\n      config.plugins.push(\n        new EvalSourceMapDevToolPlugin({\n          moduleFilenameTemplate: config.output?.devtoolModuleFilenameTemplate,\n          shouldIgnorePath,\n        })\n      )\n    }\n  }\n\n  // TODO: add codemod for \"Should not import the named export\" with JSON files\n  // config.module.strictExportPresence = !isWebpack5\n\n  return config\n})\n"],"names":["curry","COMPILER_NAMES","DevToolsIgnorePlugin","EvalSourceMapDevToolPlugin","getRspackCore","shouldIgnorePath","modulePath","includes","endsWith","base","ctx","config","mode","isDevelopment","name","isServer","isEdgeRuntime","edgeServer","server","client","target","targetWeb","devtool","serverSourceMaps","productionBrowserSourceMaps","isClient","module","rules","plugins","process","env","NEXT_RSPACK","push","moduleFilenameTemplate","output","devtoolModuleFilenameTemplate"],"mappings":"AAAA,OAAOA,WAAW,kCAAiC;AAEnD,SAASC,cAAc,QAAQ,mCAAkC;AAEjE,OAAOC,0BAA0B,4CAA2C;AAC5E,OAAOC,gCAAgC,gDAA+C;AACtF,SAASC,aAAa,QAAQ,oCAAmC;AAEjE,SAASC,iBAAiBC,UAAkB;IAC1C,OACEA,WAAWC,QAAQ,CAAC,mBACpBD,WAAWE,QAAQ,CAAC,kCACpBF,WAAWE,QAAQ,CAAC,kCACpB,2EAA2E;IAC3EF,WAAWC,QAAQ,CAAC;AAExB;AAEA,OAAO,MAAME,OAAOT,MAAM,SAASS,KACjCC,GAAyB,EACzBC,MAA6B;IAE7BA,OAAOC,IAAI,GAAGF,IAAIG,aAAa,GAAG,gBAAgB;IAClDF,OAA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