2022-06-03 20:47:16 +02:00
|
|
|
import type { webpack } from 'next/dist/compiled/webpack/webpack'
|
|
|
|
import type { NextConfigComplete } from '../../../server/config-shared'
|
|
|
|
|
2019-12-09 21:08:15 +01:00
|
|
|
import { base } from './blocks/base'
|
|
|
|
import { css } from './blocks/css'
|
2021-09-06 13:41:18 +02:00
|
|
|
import { images } from './blocks/images'
|
2019-12-09 21:08:15 +01:00
|
|
|
import { ConfigurationContext, pipe } from './utils'
|
|
|
|
|
|
|
|
export async function build(
|
|
|
|
config: webpack.Configuration,
|
|
|
|
{
|
2021-11-03 19:38:04 +01:00
|
|
|
supportedBrowsers,
|
2019-12-09 21:08:15 +01:00
|
|
|
rootDirectory,
|
|
|
|
customAppFile,
|
|
|
|
isDevelopment,
|
|
|
|
isServer,
|
2022-02-08 14:16:46 +01:00
|
|
|
isEdgeRuntime,
|
2021-10-26 18:50:56 +02:00
|
|
|
targetWeb,
|
2020-01-03 18:45:04 +01:00
|
|
|
assetPrefix,
|
2020-03-16 10:55:16 +01:00
|
|
|
sassOptions,
|
2020-05-17 22:30:42 +02:00
|
|
|
productionBrowserSourceMaps,
|
2021-01-11 18:19:56 +01:00
|
|
|
future,
|
2021-10-25 01:54:16 +02:00
|
|
|
experimental,
|
2021-11-02 21:25:12 +01:00
|
|
|
disableStaticImages,
|
2019-12-09 21:08:15 +01:00
|
|
|
}: {
|
2021-11-03 19:38:04 +01:00
|
|
|
supportedBrowsers: string[] | undefined
|
2019-12-09 21:08:15 +01:00
|
|
|
rootDirectory: string
|
2022-09-03 02:13:47 +02:00
|
|
|
customAppFile: RegExp | undefined
|
2019-12-09 21:08:15 +01:00
|
|
|
isDevelopment: boolean
|
|
|
|
isServer: boolean
|
2022-02-08 14:16:46 +01:00
|
|
|
isEdgeRuntime: boolean
|
2021-10-26 18:50:56 +02:00
|
|
|
targetWeb: boolean
|
2020-01-03 18:45:04 +01:00
|
|
|
assetPrefix: string
|
2020-03-16 10:55:16 +01:00
|
|
|
sassOptions: any
|
2020-05-17 22:30:42 +02:00
|
|
|
productionBrowserSourceMaps: boolean
|
2021-07-20 20:42:29 +02:00
|
|
|
future: NextConfigComplete['future']
|
2021-10-25 01:54:16 +02:00
|
|
|
experimental: NextConfigComplete['experimental']
|
2021-11-02 21:25:12 +01:00
|
|
|
disableStaticImages: NextConfigComplete['disableStaticImages']
|
2019-12-09 21:08:15 +01:00
|
|
|
}
|
|
|
|
): Promise<webpack.Configuration> {
|
|
|
|
const ctx: ConfigurationContext = {
|
2021-11-03 19:38:04 +01:00
|
|
|
supportedBrowsers,
|
2019-12-09 21:08:15 +01:00
|
|
|
rootDirectory,
|
|
|
|
customAppFile,
|
|
|
|
isDevelopment,
|
|
|
|
isProduction: !isDevelopment,
|
|
|
|
isServer,
|
2022-02-08 14:16:46 +01:00
|
|
|
isEdgeRuntime,
|
2019-12-09 21:08:15 +01:00
|
|
|
isClient: !isServer,
|
2021-10-26 18:50:56 +02:00
|
|
|
targetWeb,
|
2020-01-03 18:45:04 +01:00
|
|
|
assetPrefix: assetPrefix
|
|
|
|
? assetPrefix.endsWith('/')
|
|
|
|
? assetPrefix.slice(0, -1)
|
|
|
|
: assetPrefix
|
|
|
|
: '',
|
2020-03-16 10:55:16 +01:00
|
|
|
sassOptions,
|
2020-05-17 22:30:42 +02:00
|
|
|
productionBrowserSourceMaps,
|
2021-01-11 18:19:56 +01:00
|
|
|
future,
|
2021-10-25 01:54:16 +02:00
|
|
|
experimental,
|
2019-12-09 21:08:15 +01:00
|
|
|
}
|
|
|
|
|
2021-11-02 21:25:12 +01:00
|
|
|
let fns = [base(ctx), css(ctx)]
|
|
|
|
if (!disableStaticImages) {
|
|
|
|
fns.push(images(ctx))
|
|
|
|
}
|
|
|
|
const fn = pipe(...fns)
|
2019-12-09 21:08:15 +01:00
|
|
|
return fn(config)
|
|
|
|
}
|