Skip to content

Instantly share code, notes, and snippets.

@eps1lon
Last active April 30, 2024 11:33
Show Gist options
  • Save eps1lon/45f5b276da2c843855d0b72e7bde6a72 to your computer and use it in GitHub Desktop.
Save eps1lon/45f5b276da2c843855d0b72e7bde6a72 to your computer and use it in GitHub Desktop.
better Webpack stats for Next.js
const { writeFileSync } = require('fs')
const path = require('path')
const { StatsWriterPlugin } = require('webpack-stats-plugin')
/**
* @type {import('next').NextConfig}
*/
const config = {
webpack: (config, { isServer, nextRuntime, dev }) => {
config.plugins.push(
new StatsWriterPlugin({
stats: 'verbose',
transform(data) {
const json = JSON.stringify(data, null, 2)
writeFileSync(
path.join(
process.env.HOME,
'stats/react-profiling-mode',
`stats.${isServer ? 'server' : 'client'}${
nextRuntime ? `.${nextRuntime}` : ''
}.${dev ? 'dev' : 'prod'}.bad.json`
),
json
)
return json
},
})
)
return config
},
}
module.exports = config
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment