Copyright © 2025 - by Shukur Huseynli

@next/bundle-analyzerFirst, you need to install the @next/bundle-analyzer package as a development dependency. Open your terminal and run:
npm install --save-dev @next/bundle-analyzer
Next, you need to update your Next.js configuration file to include the bundle analyzer. If you're using ES modules (as with .mjs files), you will use the import syntax.
Create or update your next.config.mjs file:
// next.config.mjs
import withBundleAnalyzer from '@next/bundle-analyzer';
const bundleAnalyzer = withBundleAnalyzer({
enabled: process.env.ANALYZE === 'true',
});
const nextConfig = {};
export default bundleAnalyzer(nextConfig);
To analyze your bundle, you need to set the ANALYZE environment variable to true and then run the build command. This generates a detailed report of your bundle size.
ANALYZE=true npm run build
After the build process completes, a new report will be generated. You can find the report in the .next folder. Open the generated report in your browser to see a detailed visualization of your bundle size.
Share this