Skip to content

Commit d4c5f85

Browse files
clydinfilipesilva
authored andcommitted
fix(@angular-devkit/build-angular): control linker template sourcemapping via builder sourcemap options
This change allows the linker sourcemap behavior to be controlled by the Webpack sourcemap configuration. For example, if a vendor file is being processed and vendor sourcemaps are disabled, the linker will now skip its internal sourcemap loading and processing steps.
1 parent ab17b17 commit d4c5f85

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

packages/angular_devkit/build_angular/src/babel/presets/application.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export interface ApplicationPresetOptions {
2020
angularLinker?: {
2121
shouldLink: boolean;
2222
jitMode: boolean;
23+
sourcemap: boolean;
2324
};
2425

2526
forceES5?: boolean;
@@ -31,7 +32,8 @@ export interface ApplicationPresetOptions {
3132
type I18nDiagnostics = import('@angular/localize/src/tools/src/diagnostics').Diagnostics;
3233
function createI18nDiagnostics(reporter: DiagnosticReporter | undefined): I18nDiagnostics {
3334
// Babel currently is synchronous so import cannot be used
34-
const diagnostics: I18nDiagnostics = new (require('@angular/localize/src/tools/src/diagnostics').Diagnostics)();
35+
const diagnostics: I18nDiagnostics =
36+
new (require('@angular/localize/src/tools/src/diagnostics').Diagnostics)();
3537

3638
if (!reporter) {
3739
return diagnostics;
@@ -130,13 +132,13 @@ export default function (api: unknown, options: ApplicationPresetOptions) {
130132

131133
if (options.angularLinker?.shouldLink) {
132134
// Babel currently is synchronous so import cannot be used
133-
const {
134-
createEs2015LinkerPlugin,
135-
} = require('@angular/compiler-cli/linker/babel') as typeof import('@angular/compiler-cli/linker/babel');
135+
const { createEs2015LinkerPlugin } =
136+
require('@angular/compiler-cli/linker/babel') as typeof import('@angular/compiler-cli/linker/babel');
136137

137138
plugins.push(
138139
createEs2015LinkerPlugin({
139140
linkerJitMode: options.angularLinker.jitMode,
141+
sourceMapping: options.angularLinker.sourcemap,
140142
logger: createNgtscLogger(options.diagnosticReporter),
141143
fileSystem: {
142144
resolve: path.resolve,

packages/angular_devkit/build_angular/src/babel/webpack-loader.ts

+10
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export default custom<AngularCustomOptions>(() => {
5858
customOptions.angularLinker = {
5959
shouldLink: true,
6060
jitMode: aot !== true,
61+
sourcemap: false,
6162
};
6263
shouldProcess = true;
6364
}
@@ -140,6 +141,15 @@ export default custom<AngularCustomOptions>(() => {
140141
);
141142
}
142143

144+
// Only enable linker template sourcemapping if linker is enabled and Webpack provides
145+
// a sourcemap. This logic allows the linker sourcemap behavior to be controlled by the
146+
// Webpack sourcemap configuration. For example, if a vendor file is being processed
147+
// and vendor sourcemaps are disabled, the `inputSourceMap` property will be `undefined`
148+
// which will effectively disable linker sourcemapping for vendor files.
149+
if (customOptions.angularLinker && configuration.options.inputSourceMap) {
150+
customOptions.angularLinker.sourcemap = true;
151+
}
152+
143153
return {
144154
...configuration.options,
145155
// Workaround for https://github.com/babel/babel-loader/pull/896 is available

0 commit comments

Comments
 (0)