File size: 901 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
const { StatsWriterPlugin } = require('webpack-stats-plugin')
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer')

module.exports = {
  experimental: {
    appDir: true,
  },
  webpack: (config, options) => {
    const { nextRuntime = 'client' } = options
    if (process.env.ANALYZE) {
      if (nextRuntime === 'edge')
        config.plugins.push(
          new BundleAnalyzerPlugin({
            analyzerMode: 'static',
            openAnalyzer: true,
            reportFilename: options.isServer
              ? '../analyze/server.html'
              : './analyze/client.html',
          })
        )
      config.plugins.push(
        new StatsWriterPlugin({
          filename: `../webpack-stats-${nextRuntime}.json`,
          stats: {
            assets: true,
            chunks: true,
            modules: true,
          },
        })
      )
    }
    return config
  },
}