diff --git a/packages/angular_devkit/build_angular/src/webpack/plugins/devtools-ignore-plugin.ts b/packages/angular_devkit/build_angular/src/webpack/plugins/devtools-ignore-plugin.ts index 0840fb21566f..85bee65bac1f 100644 --- a/packages/angular_devkit/build_angular/src/webpack/plugins/devtools-ignore-plugin.ts +++ b/packages/angular_devkit/build_angular/src/webpack/plugins/devtools-ignore-plugin.ts @@ -33,13 +33,14 @@ export class DevToolsIgnorePlugin { constructor(private options: Options) {} apply(compiler: Compiler) { - const { SourceMapSource } = compiler.webpack.sources; + const { RawSource } = compiler.webpack.sources; compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => { compilation.hooks.processAssets.tap( { name: PLUGIN_NAME, stage: Compilation.PROCESS_ASSETS_STAGE_DEV_TOOLING, + additionalAssets: true, }, (assets) => { let vendorsTest: RegExp | null = null; @@ -55,16 +56,25 @@ export class DevToolsIgnorePlugin { } for (const [name, asset] of Object.entries(assets)) { - const map = asset.map() as Object & SourceMap; - if (!map) { + // Instead of using `asset.map` we process the map files RawSource. + // This is because `.map()` is slow and take several seconds. + if (!name.endsWith('.map')) { + // Ignore non map files continue; } + const mapContent = asset.source().toString(); + if (!mapContent) { + continue; + } + + const map = JSON.parse(mapContent) as SourceMap; + map[IGNORE_LIST] = Object.entries(map.sources) .filter(([, source]) => vendorsTest?.test(source) || runtimeTest?.test(source)) .map(([index]) => +index); - compilation.updateAsset(name, new SourceMapSource(asset.source(), name, map)); + compilation.updateAsset(name, new RawSource(JSON.stringify(map, undefined, 2))); } }, );