Visualizing Next.js bundles with Sonda
To analyze and visualize your Next.js bundles, you need to install the Sonda npm package and add the Sonda plugin to your Next.js configuration.
Installation
Install the package
To get started, install the Sonda package using the following command:
npm install sonda --save-dev
Add the plugin and enable source maps
Next, register the Sonda plugin for Next.js and enable source maps in the next.config.ts
file:
import Sonda from 'sonda/next';
import type { NextConfig } from 'next';
const withSondaAnalyzer = Sonda();
const config: NextConfig = {
productionBrowserSourceMaps: true
};
export default withSondaAnalyzer( config );
Sonda requires source maps to function correctly, but some other plugins may not support or generate them by default. If Sonda does not work as expected, check the documentation for the other plugins you are using to ensure source maps are enabled.
Configure the plugin
The steps above will allow you to generate your first report. However, if the report does not contain the information you need, refer to the Configuration page to explore additional options and learn how to enable them.
Generating a report for the server bundle
In addition to the options listed on the configuration page, the Next.js integration has an additional option called server
. This option enables Sonda to generate a report for the server bundle as well and it requires the experimental.serverSourceMaps
option to be enabled in the Next.js configuration.
import Sonda from 'sonda/next';
import type { NextConfig } from 'next';
const withSondaAnalyzer = Sonda( {
server: true
} );
const config: NextConfig = {
productionBrowserSourceMaps: true,
experimental: {
serverSourceMaps: true
}
};
export default withSondaAnalyzer( config );