rsnext/packages/next/build/webpack/config/index.ts
JJ Kasper 9b09b92a14
Ensure adding _app/_document HMRs correctly (#28279)
This is a follow-up to https://github.com/vercel/next.js/pull/28227 to ensure `_app` and `_document` HMR correctly when you start the dev server and then add `_app` and `_document`. 

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [x] Errors have helpful link attached, see `contributing.md`

x-ref: https://github.com/vercel/next.js/issues/27888
2021-08-19 08:12:12 +00:00

51 lines
1.2 KiB
TypeScript

import { webpack } from 'next/dist/compiled/webpack/webpack'
import { NextConfigComplete } from '../../../server/config-shared'
import { base } from './blocks/base'
import { css } from './blocks/css'
import { ConfigurationContext, pipe } from './utils'
export async function build(
config: webpack.Configuration,
{
rootDirectory,
customAppFile,
isDevelopment,
isServer,
assetPrefix,
sassOptions,
productionBrowserSourceMaps,
future,
isCraCompat,
}: {
rootDirectory: string
customAppFile: RegExp
isDevelopment: boolean
isServer: boolean
assetPrefix: string
sassOptions: any
productionBrowserSourceMaps: boolean
future: NextConfigComplete['future']
isCraCompat?: boolean
}
): Promise<webpack.Configuration> {
const ctx: ConfigurationContext = {
rootDirectory,
customAppFile,
isDevelopment,
isProduction: !isDevelopment,
isServer,
isClient: !isServer,
assetPrefix: assetPrefix
? assetPrefix.endsWith('/')
? assetPrefix.slice(0, -1)
: assetPrefix
: '',
sassOptions,
productionBrowserSourceMaps,
future,
isCraCompat,
}
const fn = pipe(base(ctx), css(ctx))
return fn(config)
}