Unverified Commit 6d7cf2a9 authored by Darsh Patel's avatar Darsh Patel Committed by GitHub

Convert profiling mode from configuration option to CLI switch (#14920)

Removed Option to enable `ReactProductionProfiling` from configuration and added a CLI switch for the same.
Users can now do `next build --profile`  to enable react production profiling. 
Also added a warning to notify users about the performance impact

Fixes: #14688
parent 8cd149c3
......@@ -97,7 +97,11 @@ export type PrerenderManifest = {
preview: __ApiPreviewProps
}
export default async function build(dir: string, conf = null): Promise<void> {
export default async function build(
dir: string,
conf = null,
reactProductionProfiling = false
): Promise<void> {
if (!(await isWriteable(dir))) {
throw new Error(
'> Build directory is not writeable. https://err.sh/vercel/next.js/build-dir-not-writeable'
......@@ -312,6 +316,7 @@ export default async function build(dir: string, conf = null): Promise<void> {
getBaseWebpackConfig(dir, {
tracer,
buildId,
reactProductionProfiling,
isServer: false,
config,
target,
......@@ -321,6 +326,7 @@ export default async function build(dir: string, conf = null): Promise<void> {
getBaseWebpackConfig(dir, {
tracer,
buildId,
reactProductionProfiling,
isServer: true,
config,
target,
......
......@@ -149,6 +149,7 @@ export default async function getBaseWebpackConfig(
pagesDir,
tracer,
target = 'server',
reactProductionProfiling = false,
entrypoints,
}: {
buildId: string
......@@ -158,6 +159,7 @@ export default async function getBaseWebpackConfig(
pagesDir: string
target?: string
tracer?: any
reactProductionProfiling?: boolean
entrypoints: WebpackEntrypoints
}
): Promise<webpack.Configuration> {
......@@ -273,7 +275,7 @@ export default async function getBaseWebpackConfig(
}
function getReactProfilingInProduction() {
if (config.reactProductionProfiling) {
if (reactProductionProfiling) {
return {
'react-dom$': 'react-dom/profiling',
'scheduler/tracing': 'scheduler/tracing-profiling',
......
......@@ -2,7 +2,7 @@
import { existsSync } from 'fs'
import arg from 'next/dist/compiled/arg/index.js'
import { resolve } from 'path'
import * as Log from '../build/output/log'
import { cliCommand } from '../bin/next'
import build from '../build'
import { printAndExit } from '../server/lib/utils'
......@@ -12,6 +12,7 @@ const nextBuild: cliCommand = (argv) => {
{
// Types
'--help': Boolean,
'--profile': Boolean,
// Aliases
'-h': '--help',
},
......@@ -29,11 +30,15 @@ const nextBuild: cliCommand = (argv) => {
<dir> represents the directory of the Next.js application.
If no directory is provided, the current directory will be used.
--profile can be used to enable React Production Profiling
`,
0
)
}
if (args['--profile']) {
Log.warn('Profiling is enabled. Note: This may affect performance')
}
const dir = resolve(args._[0] || '.')
// Check if the provided directory exists
......@@ -41,7 +46,7 @@ const nextBuild: cliCommand = (argv) => {
printAndExit(`> No such directory exists as the project root: ${dir}`)
}
build(dir)
build(dir, null, args['--profile'])
.then(() => process.exit(0))
.catch((err) => {
console.error('')
......
......@@ -49,7 +49,6 @@ const defaultConfig: { [key: string]: any } = {
profiling: false,
sprFlushToDisk: true,
reactMode: 'legacy',
reactProductionProfiling: false,
workerThreads: false,
pageEnv: false,
productionBrowserSourceMaps: false,
......
......@@ -40,7 +40,7 @@ describe('React Profiling Mode', () => {
}
`
)
await nextBuild(appDir)
await nextBuild(appDir, ['--profile'])
appPort = await findPort()
app = await nextStart(appDir, appPort)
})
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment