@@ -31,8 +31,17 @@ export interface CommonJsUsageWarnPluginOptions {
31
31
export class CommonJsUsageWarnPlugin {
32
32
private shownWarnings = new Set < string > ( ) ;
33
33
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
+ ] ;
35
40
41
+ constructor ( private options : CommonJsUsageWarnPluginOptions = { } ) {
42
+ if ( this . options . allowedDepedencies ) {
43
+ this . allowedDepedencies . push ( ...this . options . allowedDepedencies ) ;
44
+ }
36
45
}
37
46
38
47
apply ( compiler : Compiler ) {
@@ -48,7 +57,7 @@ export class CommonJsUsageWarnPlugin {
48
57
continue ;
49
58
}
50
59
51
- if ( this . options . allowedDepedencies ?. includes ( rawRequest ) ) {
60
+ if ( this . allowedDepedencies ?. includes ( rawRequest ) ) {
52
61
// Skip as this module is allowed even if it's a CommonJS.
53
62
continue ;
54
63
}
@@ -69,7 +78,9 @@ export class CommonJsUsageWarnPlugin {
69
78
}
70
79
71
80
// 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' ) ) {
73
84
const warning = `${ issuer ?. userRequest } depends on ${ rawRequest } . CommonJS or AMD dependencies can cause optimization bailouts.` ;
74
85
75
86
// Avoid showing the same warning multiple times when in 'watch' mode.
0 commit comments