Skip to content

Commit 310144d

Browse files
clydinangular-robot[bot]
authored andcommittedDec 13, 2022
fix(@angular-devkit/build-angular): only set ngDevMode when script optimizations are enabled
When using the experimental esbuild-based browser application builder, the `ngDevMode` global runtime variable was unintentionally always being set to false due to a previous bug fix that stopped the variable from being replaced with the value of true when script optimizations were disabled. By doing so, the fix caused the imported compiler-cli `GLOBAL_DEFS_FOR_TERSER_WITH_AOT` constant to take precedence which contains an `ngDevMode` value of false. To prevent this situation for development builds where a non-false `ngDevMode` is helpful to surface potential runtime problems, `GLOBAL_DEFS_FOR_TERSER_WITH_AOT` will no longer change the value of `ngDevMode`. This fix does not have any effect on production builds since `ngDevMode` would have been set to false regardless.
1 parent 216991b commit 310144d

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed
 

‎packages/angular_devkit/build_angular/src/builders/browser-esbuild/compiler-plugin.ts

+4
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,10 @@ export function createCompilerPlugin(
176176
// Skip keys that have been manually provided
177177
continue;
178178
}
179+
if (key === 'ngDevMode') {
180+
// ngDevMode is already set based on the builder's script optimization option
181+
continue;
182+
}
179183
// esbuild requires values to be a string (actual strings need to be quoted).
180184
// In this case, all provided values are booleans.
181185
build.initialOptions.define[key] = value.toString();

‎packages/angular_devkit/build_angular/src/builders/browser-esbuild/index.ts

+4
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,11 @@ function createCodeBundleOptions(
298298
),
299299
],
300300
define: {
301+
// Only set to false when script optimizations are enabled. It should not be set to true because
302+
// Angular turns `ngDevMode` into an object for development debugging purposes when not defined
303+
// which a constant true value would break.
301304
...(optimizationOptions.scripts ? { 'ngDevMode': 'false' } : undefined),
305+
// Only AOT mode is supported currently
302306
'ngJitMode': 'false',
303307
},
304308
};

0 commit comments

Comments
 (0)
Please sign in to comment.