index.js 739 B

12345678910111213141516171819202122232425
  1. module.exports =
  2. ({ enabled = true, openAnalyzer = true } = {}) =>
  3. (nextConfig = {}) => {
  4. return Object.assign({}, nextConfig, {
  5. webpack(config, options) {
  6. if (enabled) {
  7. const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer')
  8. config.plugins.push(
  9. new BundleAnalyzerPlugin({
  10. analyzerMode: 'static',
  11. openAnalyzer,
  12. reportFilename: options.isServer
  13. ? '../analyze/server.html'
  14. : './analyze/client.html',
  15. })
  16. )
  17. }
  18. if (typeof nextConfig.webpack === 'function') {
  19. return nextConfig.webpack(config, options)
  20. }
  21. return config
  22. },
  23. })
  24. }