Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Victor Porof <victorporof@chromium.org>
  • Loading branch information
victorporof committed Jul 12, 2022
1 parent 35ab733 commit c440188
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 24 deletions.
29 changes: 14 additions & 15 deletions packages/angular_devkit/build_angular/src/webpack/configs/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,19 @@ export async function getCommonConfig(wco: WebpackConfigOptions): Promise<Config
// determine hashing format
const hashFormat = getOutputHashFormat(buildOptions.outputHashing);

if (!vendorSourceMap) {
extraPlugins.push(
new DevToolsIgnorePlugin({
vendors: {
test: VENDORS_TEST,
},
runtime: !isPlatformServer && {
test: RUNTIME_TEST,
},
}),
);
}

if (buildOptions.progress) {
extraPlugins.push(new ProgressPlugin(platform));
}
Expand Down Expand Up @@ -443,21 +456,7 @@ export async function getCommonConfig(wco: WebpackConfigOptions): Promise<Config
},
},
},
plugins: [
new NamedChunksPlugin(),
new DedupeModuleResolvePlugin({ verbose }),
new DevToolsIgnorePlugin({
vendors: !vendorSourceMap &&
!!vendorChunk && {
test: VENDORS_TEST,
},
runtime: !vendorSourceMap &&
!isPlatformServer && {
test: RUNTIME_TEST,
},
}),
...extraPlugins,
],
plugins: [new NamedChunksPlugin(), new DedupeModuleResolvePlugin({ verbose }), ...extraPlugins],
node: false,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@ interface Options {
* Chrome DevTools to automatically ignore-list sources.
*/
export class DevToolsIgnorePlugin {
options: Options;

constructor(options: Options) {
this.options = options;
}
constructor(private options: Options) {}

apply(compiler: Compiler) {
const { SourceMapSource } = compiler.webpack.sources;
Expand All @@ -41,24 +37,31 @@ export class DevToolsIgnorePlugin {
additionalAssets: true,
},
(assets) => {
if (!this.options.vendors || !this.options.runtime) {
let vendorsTest: RegExp | null = null;
let runtimeTest: RegExp | null = null;
if (this.options.vendors) {
vendorsTest = this.options.vendors.test;
}
if (this.options.runtime) {
runtimeTest = this.options.runtime.test;
}
if (!vendorsTest && !runtimeTest) {
return;
}
const vendorsTest = this.options.vendors.test;
const runtimeTest = this.options.runtime.test;

for (const [name, asset] of Object.entries(assets)) {
const source = asset.source();
const map = asset.map() as Object & {
sources: string[];
[IGNORE_LIST]: number[];
};

if (!map) {
continue;
}

map[IGNORE_LIST] = Object.entries(map.sources)
.filter(([, source]) => source.match(vendorsTest) || source.match(runtimeTest))
.filter(([, source]) => vendorsTest?.test(source) || runtimeTest?.test(source))
.map(([index]) => +index);

compilation.assets[name] = new SourceMapSource(source, name, map);
Expand Down

0 comments on commit c440188

Please sign in to comment.