Skip to content

Commit a75f5db

Browse files
alan-agius4Keen Yee Liau
authored and
Keen Yee Liau
committedMar 30, 2020
fix(@angular-devkit/build-angular): don't show commonjs usage for webpack-dev-server utils
1 parent d4548d4 commit a75f5db

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed
 

‎packages/angular_devkit/build_angular/src/angular-cli-files/plugins/common-js-usage-warn-plugin.ts

+14-3
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,17 @@ export interface CommonJsUsageWarnPluginOptions {
3131
export class CommonJsUsageWarnPlugin {
3232
private shownWarnings = new Set<string>();
3333

34-
constructor(private options: CommonJsUsageWarnPluginOptions = {}) {
34+
// Allow the below depedency for HMR
35+
// tslint:disable-next-line: max-line-length
36+
// https://github.com/angular/angular-cli/blob/1e258317b1f6ec1e957ee3559cc3b28ba602f3ba/packages/angular_devkit/build_angular/src/dev-server/index.ts#L605-L638
37+
private allowedDepedencies = [
38+
'webpack/hot/dev-server',
39+
];
3540

41+
constructor(private options: CommonJsUsageWarnPluginOptions = {}) {
42+
if (this.options.allowedDepedencies) {
43+
this.allowedDepedencies.push(...this.options.allowedDepedencies);
44+
}
3645
}
3746

3847
apply(compiler: Compiler) {
@@ -48,7 +57,7 @@ export class CommonJsUsageWarnPlugin {
4857
continue;
4958
}
5059

51-
if (this.options.allowedDepedencies?.includes(rawRequest)) {
60+
if (this.allowedDepedencies?.includes(rawRequest)) {
5261
// Skip as this module is allowed even if it's a CommonJS.
5362
continue;
5463
}
@@ -69,7 +78,9 @@ export class CommonJsUsageWarnPlugin {
6978
}
7079

7180
// Only show warnings for modules from main entrypoint.
72-
if (mainIssuer?.name === 'main') {
81+
// And if the issuer request is not from 'webpack-dev-server', as 'webpack-dev-server'
82+
// will require CommonJS libraries for live reloading such as 'sockjs-node'.
83+
if (mainIssuer?.name === 'main' && !issuer?.userRequest?.includes('webpack-dev-server')) {
7384
const warning = `${issuer?.userRequest} depends on ${rawRequest}. CommonJS or AMD dependencies can cause optimization bailouts.`;
7485

7586
// Avoid showing the same warning multiple times when in 'watch' mode.

0 commit comments

Comments
 (0)
Please sign in to comment.