Update: You don't need this anymore. In v9.5, Next.js added a
--profileflag to enable React Profiler in a production build.
Enable the React Profiler during a production build in your Next.js project
npm install --save next-plugin-profileror
yarn add next-plugin-profilerCreate a next.config.js file:
// next.config.js
const withProfiler = require(`next-plugin-profiler`)({
isEnabled: process.env.ENABLE_PROFILER === `true`
});
module.exports = withProfiler({});Then you can run a build command with the environment variable:
ENABLE_PROFILER=true npm run build