UNPKG

next-bundle-analyzer

Version:
36 lines (32 loc) 1.4 kB
'use strict'; var NextBundleAnalyzerPlugin = require('./plugin/NextBundleAnalyzerPlugin.js'); var getInternalOptions = require('./plugin/utils/getInternalOptions.js'); function withNextBundleAnalyzer(options) { const internalOptions = getInternalOptions.getInternalOptions(options); const { clientOnly, enabled, reportDir } = internalOptions; let { reportFilename } = internalOptions; return (nextConfig = {}) => ({ ...nextConfig, webpack(webpackConfig, webpackOptions) { const { isServer } = webpackOptions; if ((enabled && !isServer) || !clientOnly) { if (!clientOnly) { reportFilename = isServer ? `${reportFilename}-server` : `${reportFilename}-client`; } webpackConfig.plugins.push(new NextBundleAnalyzerPlugin.NextBundleAnalyzerPlugin({ ...internalOptions, clientOnly, enabled, reportDir: isServer ? `../../${reportDir}` : `./${reportDir}`, reportFilename, })); } return typeof nextConfig.webpack === 'function' ? nextConfig.webpack(webpackConfig, webpackOptions) : webpackConfig; }, }); } module.exports = withNextBundleAnalyzer;