@@ -37,6 +37,7 @@ class DevServerPlugin {
37
37
: '' ;
38
38
/** @type {string } */
39
39
let path = '' ;
40
+
40
41
// only add the path if it is not default
41
42
if (
42
43
options . client &&
@@ -45,11 +46,13 @@ class DevServerPlugin {
45
46
) {
46
47
path = `&path=${ options . client . path } ` ;
47
48
}
49
+
48
50
/** @type {string } */
49
51
const port =
50
52
options . client && options . client . port
51
53
? `&port=${ options . client . port } `
52
54
: '' ;
55
+
53
56
/** @type {string } */
54
57
const clientEntry = `${ require . resolve (
55
58
'../../client/default/'
@@ -119,14 +122,22 @@ class DevServerPlugin {
119
122
*/
120
123
// eslint-disable-next-line no-shadow
121
124
const checkInject = ( option , _config , defaultValue ) => {
122
- if ( typeof option === 'boolean' ) return option ;
123
- if ( typeof option === 'function' ) return option ( _config ) ;
125
+ if ( typeof option === 'boolean' ) {
126
+ return option ;
127
+ }
128
+
129
+ if ( typeof option === 'function' ) {
130
+ return option ( _config ) ;
131
+ }
132
+
124
133
return defaultValue ;
125
134
} ;
126
135
127
136
const compilerOptions = compiler . options ;
137
+
128
138
compilerOptions . plugins = compilerOptions . plugins || [ ] ;
129
- /** @type {Boolean } */
139
+
140
+ /** @type {boolean } */
130
141
const isWebTarget = compilerOptions . externalsPresets
131
142
? compilerOptions . externalsPresets . web
132
143
: [
@@ -138,6 +149,7 @@ class DevServerPlugin {
138
149
undefined ,
139
150
null ,
140
151
] . includes ( compilerOptions . target ) ;
152
+
141
153
/** @type {Entry } */
142
154
const additionalEntries = checkInject (
143
155
options . injectClient ,
@@ -153,24 +165,12 @@ class DevServerPlugin {
153
165
154
166
// use a hook to add entries if available
155
167
if ( EntryPlugin ) {
156
- compiler . hooks . make . tapPromise ( 'DevServerPlugin' , ( compilation ) =>
157
- Promise . all (
158
- additionalEntries . map (
159
- ( entry ) =>
160
- new Promise ( ( resolve , reject ) => {
161
- compilation . addEntry (
162
- compiler . context ,
163
- EntryPlugin . createDependency ( entry , { } ) ,
164
- { } , // global entry
165
- ( err ) => {
166
- if ( err ) return reject ( err ) ;
167
- resolve ( ) ;
168
- }
169
- ) ;
170
- } )
171
- )
172
- )
173
- ) ;
168
+ for ( const additionalEntry of additionalEntries ) {
169
+ new EntryPlugin ( compiler . context , additionalEntry , {
170
+ // eslint-disable-next-line no-undefined
171
+ name : undefined ,
172
+ } ) . apply ( compiler ) ;
173
+ }
174
174
} else {
175
175
compilerOptions . entry = prependEntry (
176
176
compilerOptions . entry || './src' ,
@@ -185,6 +185,7 @@ class DevServerPlugin {
185
185
const providePlugin = new webpack . ProvidePlugin ( {
186
186
__webpack_dev_server_client__ : getSocketClientPath ( options ) ,
187
187
} ) ;
188
+
188
189
providePlugin . apply ( compiler ) ;
189
190
190
191
if (
@@ -195,6 +196,7 @@ class DevServerPlugin {
195
196
) {
196
197
// apply the HMR plugin, if it didn't exist before.
197
198
const plugin = new webpack . HotModuleReplacementPlugin ( ) ;
199
+
198
200
plugin . apply ( compiler ) ;
199
201
}
200
202
}
0 commit comments