rsnext/packages/next/build/webpack/config/blocks/base.ts
Shu Ding bc19c2a564
Fix code splitting and build target for the server-web build (#30972)
- Code splitting should be disabled for the server-web build. Done via `ServerlessPlugin`.
- ~Target can't be `web`, `webworker` is better.~ Using `web` and `es6` for now, still not ideal.
- https://github.com/acornjs/acorn/issues/970

## Bug

- [ ] Related issues linked using `fixes #number`
- [x] 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 `yarn lint`
2021-11-05 03:27:02 +00:00

53 lines
1.6 KiB
TypeScript

import curry from 'next/dist/compiled/lodash.curry'
import { webpack } from 'next/dist/compiled/webpack/webpack'
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.webServerRuntime
? 'server-web'
: 'server'
: 'client'
// @ts-ignore TODO webpack 5 typings
config.target = !ctx.targetWeb
? 'node12.22'
: ctx.webServerRuntime
? ['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 {
if (!ctx.webServerRuntime) {
// `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 {
// Enable browser sourcemaps:
if (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
})