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

fix(@angular-devkit/build-angular): control linker template sourcemapping via builder sourcemap options #21155

Merged
merged 1 commit into from Jun 21, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
Expand Up @@ -20,6 +20,7 @@ export interface ApplicationPresetOptions {
angularLinker?: {
shouldLink: boolean;
jitMode: boolean;
sourcemap: boolean;
};

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

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

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

plugins.push(
createEs2015LinkerPlugin({
linkerJitMode: options.angularLinker.jitMode,
sourceMapping: options.angularLinker.sourcemap,
logger: createNgtscLogger(options.diagnosticReporter),
fileSystem: {
resolve: path.resolve,
Expand Down
10 changes: 10 additions & 0 deletions packages/angular_devkit/build_angular/src/babel/webpack-loader.ts
Expand Up @@ -58,6 +58,7 @@ export default custom<AngularCustomOptions>(() => {
customOptions.angularLinker = {
shouldLink: true,
jitMode: aot !== true,
sourcemap: false,
};
shouldProcess = true;
}
Expand Down Expand Up @@ -140,6 +141,15 @@ export default custom<AngularCustomOptions>(() => {
);
}

// Only enable linker template sourcemapping if linker is enabled and Webpack provides
// a sourcemap. This logic 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 `inputSourceMap` property will be `undefined`
// which will effectively disable linker sourcemapping for vendor files.
if (customOptions.angularLinker && configuration.options.inputSourceMap) {
customOptions.angularLinker.sourcemap = true;
}

return {
...configuration.options,
// Workaround for https://github.com/babel/babel-loader/pull/896 is available
Expand Down