Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add --no-mangling to next build + fix --profile option #42633

Merged
merged 8 commits into from Nov 8, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/next/build/index.ts
Expand Up @@ -254,7 +254,8 @@ export default async function build(
conf = null,
reactProductionProfiling = false,
debugOutput = false,
runLint = true
runLint = true,
noMangling = false
): Promise<void> {
try {
const nextBuildSpan = trace('next-build', undefined, {
Expand Down Expand Up @@ -932,6 +933,7 @@ export default async function build(
runWebpackSpan,
target,
appDir,
noMangling,
middlewareMatchers: entrypoints.middlewareMatchers,
}

Expand Down
11 changes: 8 additions & 3 deletions packages/next/build/webpack-config.ts
Expand Up @@ -579,6 +579,7 @@ export default async function getBaseWebpackConfig(
target = COMPILER_NAMES.server,
appDir,
middlewareMatchers,
noMangling = false,
}: {
buildId: string
config: NextConfigComplete
Expand All @@ -593,6 +594,7 @@ export default async function getBaseWebpackConfig(
target?: string
appDir?: string
middlewareMatchers?: MiddlewareMatcher[]
noMangling?: boolean
}
): Promise<webpack.Configuration> {
const isClient = compilerType === COMPILER_NAMES.client
Expand Down Expand Up @@ -968,6 +970,7 @@ export default async function getBaseWebpackConfig(
plugins: [],
}

console.log(noMangling)
feedthejim marked this conversation as resolved.
Show resolved Hide resolved
const terserOptions: any = {
parse: {
ecma: 8,
Expand All @@ -981,7 +984,7 @@ export default async function getBaseWebpackConfig(
},
mangle: {
safari10: true,
...(process.env.__NEXT_MANGLING_DEBUG
...(process.env.__NEXT_MANGLING_DEBUG || noMangling
? {
toplevel: true,
module: true,
Expand All @@ -996,7 +999,7 @@ export default async function getBaseWebpackConfig(
comments: false,
// Fixes usage of Emoji and certain Regex
ascii_only: true,
...(process.env.__NEXT_MANGLING_DEBUG
...(process.env.__NEXT_MANGLING_DEBUG || noMangling
? {
beautify: true,
}
Expand Down Expand Up @@ -1753,7 +1756,9 @@ export default async function getBaseWebpackConfig(
resolve: {
alias: {
react: 'next/dist/compiled/react',
'react-dom$': 'next/dist/compiled/react-dom',
'react-dom$': reactProductionProfiling
? 'next/dist/compiled/react-dom/cjs/react-dom.profiling.min'
: 'next/dist/compiled/react-dom',
'react-dom/client$':
'next/dist/compiled/react-dom/client',
},
Expand Down
8 changes: 7 additions & 1 deletion packages/next/cli/next-build.ts
Expand Up @@ -15,6 +15,7 @@ const nextBuild: cliCommand = (argv) => {
'--profile': Boolean,
'--debug': Boolean,
'--no-lint': Boolean,
'--no-mangling': Boolean,
// Aliases
'-h': '--help',
'-d': '--debug',
Expand Down Expand Up @@ -44,6 +45,7 @@ const nextBuild: cliCommand = (argv) => {
Options
--profile Can be used to enable React Production Profiling
--no-lint Disable linting
--no-mangling Disable mangling
`,
0
)
Expand All @@ -54,6 +56,9 @@ const nextBuild: cliCommand = (argv) => {
if (args['--no-lint']) {
Log.warn('Linting is disabled')
}
if (args['--no-mangling']) {
Log.warn('Mangling is disabled')
feedthejim marked this conversation as resolved.
Show resolved Hide resolved
}
const dir = getProjectDir(args._[0])

// Check if the provided directory exists
Expand All @@ -66,7 +71,8 @@ const nextBuild: cliCommand = (argv) => {
null,
args['--profile'],
args['--debug'],
!args['--no-lint']
!args['--no-lint'],
args['--no-mangling']
).catch((err) => {
console.error('')
if (
Expand Down