NextJS project serverless output folder has huge bundle size (200MB+)

Having the following picture (.next/serverless folder size is 253MB):

What can cause that?

1 Like

Removing the following line from next.config.js file:

    // For limiting js chunk files
    config.plugins.push(
      new webpack.optimize.LimitChunkCountPlugin({
        maxChunks: 1,
      }),
    );

and adding this:

    // Minify serverless output scripts (reduces files size)
    config.optimization.minimize = true;

reduced serverless folder bundle size from 253MB to just 33MB:

du -h -d 0 .xdn/lambda/.next/serverless                            ✔       12.19.0   
 33M    .xdn/lambda/.next/serverless

In addition, webpack-bundle-analyzer - npm can be used to optimize bundles

The next bundle analyzer plugin makes it easy to the use the webpack bundle analyzer.