rsnext/packages/next-bundle-analyzer/index.js
quisi.do 19fa1fa579
add logLevel support to @next/bundle-analyzer (#59228)
Co-authored-by: Jiachi Liu <inbox@huozhi.im>
2023-12-06 23:21:23 +01:00

28 lines
904 B
JavaScript

module.exports =
({ enabled = true, logLevel, openAnalyzer, analyzerMode } = {}) =>
(nextConfig = {}) => {
return Object.assign({}, nextConfig, {
webpack(config, options) {
if (enabled) {
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer')
config.plugins.push(
new BundleAnalyzerPlugin({
analyzerMode: analyzerMode || 'static',
logLevel,
openAnalyzer,
reportFilename: !options.nextRuntime
? `./analyze/client.html`
: `../${options.nextRuntime === 'nodejs' ? '../' : ''}analyze/${
options.nextRuntime
}.html`,
})
)
}
if (typeof nextConfig.webpack === 'function') {
return nextConfig.webpack(config, options)
}
return config
},
})
}