Last active
April 30, 2024 11:33
-
-
Save eps1lon/45f5b276da2c843855d0b72e7bde6a72 to your computer and use it in GitHub Desktop.
better Webpack stats for Next.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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