mirror of
https://github.com/hanzoai/next.js.git
synced 2026-09-24 17:00:51 +00:00
Point next/bundle-analyzer users at the new one when running with turbopack 
42 lines
1.4 KiB
JavaScript
42 lines
1.4 KiB
JavaScript
module.exports =
|
|
({ enabled = true, logLevel, openAnalyzer, analyzerMode } = {}) =>
|
|
(nextConfig = {}) => {
|
|
if (!enabled) {
|
|
return nextConfig
|
|
}
|
|
if (process.env.TURBOPACK) {
|
|
console.warn(
|
|
'The Next Bundle Analyzer is not compatible with Turbopack builds, no report will be generated.\n\n' +
|
|
'Consider trying the new Turbopack analyzer via `next experimental-analyze`.\n\n' +
|
|
'See https://nextjs.org/docs/app/guides/package-bundling for more information\n\n' +
|
|
'To run this analysis pass the `--webpack` flag to `next build`'
|
|
)
|
|
return nextConfig
|
|
}
|
|
|
|
const extension = analyzerMode === 'json' ? '.json' : '.html'
|
|
|
|
return Object.assign({}, nextConfig, {
|
|
webpack(config, options) {
|
|
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer')
|
|
config.plugins.push(
|
|
new BundleAnalyzerPlugin({
|
|
analyzerMode: analyzerMode || 'static',
|
|
logLevel,
|
|
openAnalyzer,
|
|
reportFilename: !options.nextRuntime
|
|
? `./analyze/client${extension}`
|
|
: `../${options.nextRuntime === 'nodejs' ? '../' : ''}analyze/${
|
|
options.nextRuntime
|
|
}${extension}`,
|
|
})
|
|
)
|
|
|
|
if (typeof nextConfig.webpack === 'function') {
|
|
return nextConfig.webpack(config, options)
|
|
}
|
|
return config
|
|
},
|
|
})
|
|
}
|