Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5d46d6e

Browse files
alan-agius4clydin
authored andcommitted
fix(@angular/build): preserve names in esbuild for improved debugging in dev mode
This commit introduces the `keepNames` option in esbuild configurations for both application code bundling and Vite utility functions. By setting `keepNames` to `true` (or conditionally based on optimization settings), function and variable names are preserved during the build process. This significantly improves the debugging experience in **development mode** by ensuring that original names are retained in compiled output, leading to more readable stack traces and easier identification of code sections during development. (cherry picked from commit 58da860)
1 parent 5a9503b commit 5d46d6e

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

packages/angular/build/src/tools/esbuild/application-code-bundle.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,9 @@ function getEsBuildCommonOptions(options: NormalizedApplicationBuildOptions): Bu
607607
}
608608
}
609609

610+
const minifySyntax = optimizationOptions.scripts;
611+
const minifyIdentifiers = minifySyntax && allowMangle;
612+
610613
return {
611614
absWorkingDir: workspaceRoot,
612615
format: 'esm',
@@ -618,9 +621,10 @@ function getEsBuildCommonOptions(options: NormalizedApplicationBuildOptions): Bu
618621
metafile: true,
619622
legalComments: options.extractLicenses ? 'none' : 'eof',
620623
logLevel: options.verbose && !jsonLogs ? 'debug' : 'silent',
621-
minifyIdentifiers: optimizationOptions.scripts && allowMangle,
622-
minifySyntax: optimizationOptions.scripts,
623-
minifyWhitespace: optimizationOptions.scripts,
624+
keepNames: !minifyIdentifiers,
625+
minifyIdentifiers,
626+
minifySyntax,
627+
minifyWhitespace: minifySyntax,
624628
pure: ['forwardRef'],
625629
outdir: workspaceRoot,
626630
outExtension: outExtension ? { '.js': `.${outExtension}` } : undefined,
@@ -637,7 +641,7 @@ function getEsBuildCommonOptions(options: NormalizedApplicationBuildOptions): Bu
637641
// Only set to false when script optimizations are enabled. It should not be set to true because
638642
// Angular turns `ngDevMode` into an object for development debugging purposes when not defined
639643
// which a constant true value would break.
640-
...(optimizationOptions.scripts ? { 'ngDevMode': 'false' } : undefined),
644+
...(minifySyntax ? { 'ngDevMode': 'false' } : undefined),
641645
'ngJitMode': jit ? 'true' : 'false',
642646
'ngServerMode': 'false',
643647
'ngHmrMode': options.templateUpdates ? 'true' : 'false',

packages/angular/build/src/tools/vite/utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ export function getDepOptimizationConfig({
9898
esbuildOptions: {
9999
// Set esbuild supported targets.
100100
target,
101+
keepNames: true,
101102
supported: getFeatureSupport(target, zoneless),
102103
plugins,
103104
loader,

tests/legacy-cli/e2e/tests/build/prerender/error-with-sourcemaps.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,6 @@ export default async function () {
4848
message,
4949
// When babel is used it will add names to the sourcemap and `constructor` will be used in the stack trace.
5050
// This will currently only happen if AOT and script optimizations are set which enables advanced optimizations.
51-
/window is not defined[.\s\S]*(?:constructor|_App) \(.*app\.ts\:\d+:\d+\)/,
51+
/window is not defined[.\s\S]*(?:constructor|App) \(.*app\.ts\:\d+:\d+\)/,
5252
);
5353
}

0 commit comments

Comments
 (0)