Skip to content

Commit

Permalink
Allow configuring analyzerMode in bundle-analyzer (#47468)
Browse files Browse the repository at this point in the history
It's valid to want to output JSON instead of HTML for the bundle
analyzer so we can expose this specific config the same as
`openAnalyzer`. cc @mknichel
  • Loading branch information
ijjk authored Jun 14, 2023
1 parent 40ce621 commit 115b6ad
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
9 changes: 5 additions & 4 deletions packages/next-bundle-analyzer/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import type { NextConfig } from 'next'

declare const NextBundleAnalyzer =
(options?: { enabled?: boolean; openAnalyzer?: boolean }) =>
(config?: NextConfig) =>
NextConfig
declare function NextBundleAnalyzer(options?: {
enabled?: boolean
openAnalyzer?: boolean
analyzerMode?: 'json' | 'static'
}): (config?: NextConfig) => NextConfig

export = NextBundleAnalyzer
4 changes: 2 additions & 2 deletions packages/next-bundle-analyzer/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
module.exports =
({ enabled = true, openAnalyzer = true } = {}) =>
({ enabled = true, openAnalyzer, analyzerMode } = {}) =>
(nextConfig = {}) => {
return Object.assign({}, nextConfig, {
webpack(config, options) {
if (enabled) {
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer')
config.plugins.push(
new BundleAnalyzerPlugin({
analyzerMode: 'static',
analyzerMode: analyzerMode || 'static',
openAnalyzer,
reportFilename: !options.nextRuntime
? `./analyze/client.html`
Expand Down

0 comments on commit 115b6ad

Please sign in to comment.