next-plugin-bundle-stats
Version:
In-depth bundle analyzer for webpack(bundle size, assets, modules)
27 lines (21 loc) • 676 B
JavaScript
const { BundleStatsWebpackPlugin } = require('bundle-stats-webpack-plugin');
module.exports = (pluginOptions = {}) => (nextConfig = {}) => ({
...nextConfig,
webpack(config, options) {
if (!options.defaultLoaders) {
throw new Error(
'This plugin is not compatible with Next.js versions below 5.0.0 https://err.sh/next-plugins/upgrade',
);
}
const { dev, isServer } = options;
if (!dev && !isServer) {
config.plugins.push(
new BundleStatsWebpackPlugin(pluginOptions),
);
}
if (typeof nextConfig.webpack === 'function') {
return nextConfig.webpack(config, options);
}
return config;
},
});