rsnext/packages/next-bundle-analyzer/index.js
Jiachi Liu b180becad5
Update bundle analyzer dependency and output (#42797)
* Update `webpack-bundle-analyzer` to 4.7.0
* Change the output file paths of bundle analyzing results to
`./next/analyze/<nodejs|edge|client>.html`
2022-11-11 16:39:45 -08:00

27 lines
847 B
JavaScript

module.exports =
({ enabled = true, openAnalyzer = true } = {}) =>
(nextConfig = {}) => {
return Object.assign({}, nextConfig, {
webpack(config, options) {
if (enabled) {
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer')
config.plugins.push(
new BundleAnalyzerPlugin({
analyzerMode: 'static',
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
},
})
}