Skip to content

Commit 9fd3562

Browse files
committed
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. (cherry picked from commit 310144d)
1 parent ccc8e03 commit 9fd3562

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
@@ -192,6 +192,10 @@ export function createCompilerPlugin(
192192
// Skip keys that have been manually provided
193193
continue;
194194
}
195+
if (key === 'ngDevMode') {
196+
// ngDevMode is already set based on the builder's script optimization option
197+
continue;
198+
}
195199
// esbuild requires values to be a string (actual strings need to be quoted).
196200
// In this case, all provided values are booleans.
197201
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
@@ -296,7 +296,11 @@ function createCodeBundleOptions(
296296
),
297297
],
298298
define: {
299+
// Only set to false when script optimizations are enabled. It should not be set to true because
300+
// Angular turns `ngDevMode` into an object for development debugging purposes when not defined
301+
// which a constant true value would break.
299302
...(optimizationOptions.scripts ? { 'ngDevMode': 'false' } : undefined),
303+
// Only AOT mode is supported currently
300304
'ngJitMode': 'false',
301305
},
302306
};

0 commit comments

Comments
 (0)