|
|
import curry from 'next/dist/compiled/lodash.curry' |
|
|
import type { webpack } from 'next/dist/compiled/webpack/webpack' |
|
|
import { COMPILER_NAMES } from '../../../../shared/lib/constants' |
|
|
import type { ConfigurationContext } from '../utils' |
|
|
import DevToolsIgnorePlugin from '../../plugins/devtools-ignore-list-plugin' |
|
|
import EvalSourceMapDevToolPlugin from '../../plugins/eval-source-map-dev-tool-plugin' |
|
|
import { getRspackCore } from '../../../../shared/lib/get-rspack' |
|
|
|
|
|
function shouldIgnorePath(modulePath: string): boolean { |
|
|
return ( |
|
|
modulePath.includes('node_modules') || |
|
|
modulePath.endsWith('__nextjs-internal-proxy.cjs') || |
|
|
modulePath.endsWith('__nextjs-internal-proxy.mjs') || |
|
|
|
|
|
modulePath.includes('next/dist') |
|
|
) |
|
|
} |
|
|
|
|
|
export const base = curry(function base( |
|
|
ctx: ConfigurationContext, |
|
|
config: webpack.Configuration |
|
|
) { |
|
|
config.mode = ctx.isDevelopment ? 'development' : 'production' |
|
|
config.name = ctx.isServer |
|
|
? ctx.isEdgeRuntime |
|
|
? COMPILER_NAMES.edgeServer |
|
|
: COMPILER_NAMES.server |
|
|
: COMPILER_NAMES.client |
|
|
|
|
|
config.target = !ctx.targetWeb |
|
|
? 'node18.17' |
|
|
: ctx.isEdgeRuntime |
|
|
? ['web', 'es6'] |
|
|
: ['web', 'es6'] |
|
|
|
|
|
|
|
|
if (ctx.isDevelopment) { |
|
|
if (process.env.__NEXT_TEST_MODE && !process.env.__NEXT_TEST_WITH_DEVTOOL) { |
|
|
config.devtool = false |
|
|
} else { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
config.devtool = 'eval-source-map' |
|
|
} |
|
|
} else { |
|
|
if ( |
|
|
ctx.isEdgeRuntime || |
|
|
(ctx.isServer && ctx.serverSourceMaps) || |
|
|
|
|
|
(ctx.productionBrowserSourceMaps && ctx.isClient) |
|
|
) { |
|
|
config.devtool = 'source-map' |
|
|
} else { |
|
|
config.devtool = false |
|
|
} |
|
|
} |
|
|
|
|
|
if (!config.module) { |
|
|
config.module = { rules: [] } |
|
|
} |
|
|
|
|
|
config.plugins ??= [] |
|
|
if (config.devtool === 'source-map' && !process.env.NEXT_RSPACK) { |
|
|
config.plugins.push( |
|
|
new DevToolsIgnorePlugin({ |
|
|
shouldIgnorePath, |
|
|
}) |
|
|
) |
|
|
} else if (config.devtool === 'eval-source-map') { |
|
|
|
|
|
config.devtool = false |
|
|
if (process.env.NEXT_RSPACK) { |
|
|
config.plugins.push( |
|
|
new (getRspackCore().EvalSourceMapDevToolPlugin)({ |
|
|
moduleFilenameTemplate: config.output?.devtoolModuleFilenameTemplate, |
|
|
}) |
|
|
) |
|
|
} else { |
|
|
config.plugins.push( |
|
|
new EvalSourceMapDevToolPlugin({ |
|
|
moduleFilenameTemplate: config.output?.devtoolModuleFilenameTemplate, |
|
|
shouldIgnorePath, |
|
|
}) |
|
|
) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return config |
|
|
}) |
|
|
|