package
Use `webpack-bundle-analyzer` in your Next.js project
npm install @next/bundle-analyzerGitHub-flavored package documentation.
Across all versions.
Download trend unavailable.
Runtime metadata.
Latest published Nov 9, 2026
canary
matt.straka
matt.j.straka@gmail.com
Estimated unpacked size across 15 packages.
2.6 MB
Includes dependencies.
Use webpack-bundle-analyzer in your Next.js project
npm install @next/bundle-analyzeror
yarn add @next/bundle-analyzerNote: if installing as a devDependency make sure to wrap the require in a process.env check as next.config.js is loaded during next start as well.
Create a next.config.js (and make sure you have next-bundle-analyzer set up)
const withBundleAnalyzer = require('@next/bundle-analyzer')({
enabled: process.env.ANALYZE === 'true',
})
module.exports = withBundleAnalyzer({})Or configuration as a function:
module.exports = (phase, defaultConfig) => {
return withBundleAnalyzer(defaultConfig)
}Then you can run the command below:
# Analyze is done on build when env var is set
ANALYZE=true yarn buildWhen enabled three HTML files (client.html, edge.html and nodejs.html) will be outputted to <distDir>/analyze/. One will be for the nodejs server bundle, one for the edge server bundle, and one for the browser bundle.
To disable automatically opening the report in your default browser, set openAnalyzer to false:
const withBundleAnalyzer = require('@next/bundle-analyzer')({
enabled: process.env.ANALYZE === 'true',
openAnalyzer: false,
})
module.exports = withBundleAnalyzer({})From version 2.0.0 of next-compose-plugins you need to call bundle-analyzer in this way to work
const withPlugins = require('next-compose-plugins')
const withBundleAnalyzer = require('@next/bundle-analyzer')({
enabled: process.env.ANALYZE === 'true',
})
module.exports = withPlugins([
[withBundleAnalyzer],
// your other plugins here
])