b5aa571c71
WIP. ## Bug - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Errors have helpful link attached, see `contributing.md` ## Feature - [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Documentation added - [ ] Telemetry added. In case of a feature if it's used or not. - [ ] Errors have helpful link attached, see `contributing.md` ## Documentation / Examples - [ ] Make sure the linting passes by running `pnpm lint` - [ ] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples) Co-authored-by: Shu Ding <3676859+shuding@users.noreply.github.com>
55 lines
1.7 KiB
TypeScript
55 lines
1.7 KiB
TypeScript
import curry from 'next/dist/compiled/lodash.curry'
|
|
import { webpack } from 'next/dist/compiled/webpack/webpack'
|
|
import { COMPILER_NAMES } from '../../../../shared/lib/constants'
|
|
import { ConfigurationContext } from '../utils'
|
|
|
|
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
|
|
|
|
// @ts-ignore TODO webpack 5 typings
|
|
config.target = !ctx.targetWeb
|
|
? 'node12.22'
|
|
: ctx.isEdgeRuntime
|
|
? ['web', 'es6']
|
|
: ['web', 'es5']
|
|
|
|
// https://webpack.js.org/configuration/devtool/#development
|
|
if (ctx.isDevelopment) {
|
|
if (process.env.__NEXT_TEST_MODE && !process.env.__NEXT_TEST_WITH_DEVTOOL) {
|
|
config.devtool = false
|
|
} else {
|
|
// `eval-source-map` provides full-fidelity source maps for the
|
|
// original source, including columns and original variable names.
|
|
// This is desirable so the in-browser debugger can correctly pause
|
|
// and show scoped variables with their original names.
|
|
config.devtool = 'eval-source-map'
|
|
}
|
|
} else {
|
|
if (
|
|
ctx.isEdgeRuntime ||
|
|
// Enable browser sourcemaps:
|
|
(ctx.productionBrowserSourceMaps && ctx.isClient)
|
|
) {
|
|
config.devtool = 'source-map'
|
|
} else {
|
|
config.devtool = false
|
|
}
|
|
}
|
|
|
|
if (!config.module) {
|
|
config.module = { rules: [] }
|
|
}
|
|
|
|
// TODO: add codemod for "Should not import the named export" with JSON files
|
|
// config.module.strictExportPresence = !isWebpack5
|
|
|
|
return config
|
|
})
|