Unverified Commit 75c62cb7 authored by Tobias Koppers's avatar Tobias Koppers Committed by GitHub

add env var to enable advanced webpack logging and profiling (#23178)

This allows to use `__NEXT_WEBPACK_LOGGING` to enable verbose webpack logging output to investigate into performance and cache problems.

`__NEXT_WEBPACK_LOGGING=1` enables some basic logging

`__NEXT_WEBPACK_LOGGING=infrastructure` enables only infrastructure logging

`__NEXT_WEBPACK_LOGGING=profile-client` enables deep profile output of the client build

`__NEXT_WEBPACK_LOGGING=profile-server` same for the server

`__NEXT_WEBPACK_LOGGING=profile-client,infrastructure` combines multiple things
parent f827bf0c
......@@ -1235,6 +1235,7 @@ export default async function getBaseWebpackConfig(
assetPrefix: config.assetPrefix,
target,
reactProductionProfiling,
webpack: !!config.webpack,
})
const cache: any = {
......@@ -1257,6 +1258,55 @@ export default async function getBaseWebpackConfig(
// @ts-ignore TODO: remove ignore when webpack 5 is stable
webpackConfig.optimization.realContentHash = false
if (process.env.__NEXT_WEBPACK_LOGGING) {
const logInfra = process.env.__NEXT_WEBPACK_LOGGING.includes(
'infrastructure'
)
const logProfileClient = process.env.__NEXT_WEBPACK_LOGGING.includes(
'profile-client'
)
const logProfileServer = process.env.__NEXT_WEBPACK_LOGGING.includes(
'profile-server'
)
const logDefault = !logInfra && !logProfileClient && !logProfileServer
if (logDefault || logInfra) {
// @ts-ignore TODO: remove ignore when webpack 5 is stable
webpackConfig.infrastructureLogging = {
level: 'verbose',
debug: /FileSystemInfo/,
}
}
if (
logDefault ||
(logProfileClient && !isServer) ||
(logProfileServer && isServer)
) {
webpackConfig.plugins!.push((compiler: webpack.Compiler) => {
compiler.hooks.done.tap('next-webpack-logging', (stats) => {
console.log(
stats.toString({
colors: true,
// @ts-ignore TODO: remove ignore when webpack 5 is stable
logging: logDefault ? 'log' : 'verbose',
})
)
})
})
}
if ((logProfileClient && !isServer) || (logProfileServer && isServer)) {
webpackConfig.plugins!.push(
new webpack.ProgressPlugin({
// @ts-ignore TODO: remove ignore when webpack 5 is stable
profile: true,
})
)
webpackConfig.profile = true
}
}
}
webpackConfig = await buildConfiguration(webpackConfig, {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment