Skip to content

Commit d71ee21

Browse files
alan-agius4filipesilva
authored andcommitted
fix(@angular-devkit/build-angular): apply local libraries sourcemap without vendor: true
With this change we apply sourcemaps of libraries in a monorepo without the need to enable `vendor: true`. This is more intuitive behavior and in line with what the users expect. We also suppress the `Failed to parse source map from` in-actionable warning. Closes #11305
1 parent 535a507 commit d71ee21

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

packages/angular_devkit/build_angular/src/webpack/configs/common.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import {
4747
WebpackRollupLoader,
4848
} from '../plugins';
4949
import { getEsVersionForFileName, getOutputHashFormat, getWatchOptions, normalizeExtraEntryPoints } from '../utils/helpers';
50+
import { IGNORE_WARNINGS } from '../utils/stats';
5051

5152
const TerserPlugin = require('terser-webpack-plugin');
5253
const PnpWebpackPlugin = require('pnp-webpack-plugin');
@@ -366,10 +367,12 @@ export function getCommonConfig(wco: WebpackConfigOptions): Configuration {
366367
extraPlugins.push(new BundleBudgetPlugin({ budgets: buildOptions.budgets }));
367368
}
368369

369-
if ((scriptsSourceMap || stylesSourceMap) && vendorSourceMap) {
370+
if ((scriptsSourceMap || stylesSourceMap)) {
370371
extraRules.push({
371372
test: /\.m?js$/,
372-
exclude: /(ngfactory|ngstyle)\.js$/,
373+
exclude: vendorSourceMap
374+
? /(ngfactory|ngstyle)\.js$/
375+
: [/[\\\/]node_modules[\\\/]/, /(ngfactory|ngstyle)\.js$/],
373376
enforce: 'pre',
374377
loader: require.resolve('source-map-loader'),
375378
});
@@ -512,6 +515,7 @@ export function getCommonConfig(wco: WebpackConfigOptions): Configuration {
512515
performance: {
513516
hints: false,
514517
},
518+
...withWebpackFourOrFive({}, { ignoreWarnings: IGNORE_WARNINGS }),
515519
module: {
516520
// Show an error for missing exports instead of a warning.
517521
strictExportPresence: true,

packages/angular_devkit/build_angular/src/webpack/utils/stats.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import * as path from 'path';
1313
import * as textTable from 'text-table';
1414
import { colors as ansiColors, removeColor } from '../../utils/color';
1515
import { Configuration, Stats } from 'webpack';
16+
import { isWebpackFiveOrHigher } from '../../utils/webpack-version';
1617

1718
export function formatSize(size: number): string {
1819
if (size <= 0) {
@@ -212,11 +213,19 @@ function statsToString(json: any, statsConfig: any, bundleState?: BundleStats[])
212213
}
213214
}
214215

215-
const ERRONEOUS_WARNINGS_FILTER = (warning: string) => ![
216+
export const IGNORE_WARNINGS = [
216217
// Webpack 5+ has no facility to disable this warning.
217218
// System.import is used in @angular/core for deprecated string-form lazy routes
218219
/System.import\(\) is deprecated and will be removed soon/i,
219-
].some(msg => msg.test(warning));
220+
// https://github.com/webpack-contrib/source-map-loader/blob/b2de4249c7431dd8432da607e08f0f65e9d64219/src/index.js#L83
221+
/Failed to parse source map from/,
222+
];
223+
224+
// TODO: remove when Webpack 4 is no longer supported.
225+
// See: https://webpack.js.org/configuration/other-options/#ignorewarnings
226+
const ERRONEOUS_WARNINGS_FILTER = isWebpackFiveOrHigher()
227+
? (warning: string) => warning
228+
: (warning: string) => !IGNORE_WARNINGS.some(msg => msg.test(warning));
220229

221230
interface WebpackDiagnostic {
222231
message: string;

0 commit comments

Comments
 (0)