rsnext/packages/next-bundle-analyzer
2020-07-22 02:20:02 -04:00
..
index.js Improve linting rules to catch more errors (#9374) 2019-11-10 19:24:53 -08:00
package.json v9.4.5-canary.43 2020-07-22 02:20:02 -04:00
readme.md Update next-bundle-analyzer readme (#14976) 2020-07-09 08:24:21 +00:00

Next.js + Webpack Bundle Analyzer

Use webpack-bundle-analyzer in your Next.js project

Installation

npm install @next/bundle-analyzer

or

yarn add @next/bundle-analyzer

Usage with environment variables

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 build

When enabled two HTML files (client.html and server.html) will be outputted to <distDir>/analyze/. One will be for the server bundle, one for the browser bundle.