@@ -6,20 +6,31 @@ class ServeCommand {
6
6
const { logger, webpack } = cli ;
7
7
8
8
const loadDevServerOptions = ( ) => {
9
+ // TODO simplify this after drop webpack v4 and webpack-dev-server v3
9
10
// eslint-disable-next-line @typescript-eslint/no-var-requires, node/no-extraneous-require
10
11
const devServer = require ( "webpack-dev-server" ) ;
12
+ const isNewDevServerCLIAPI = typeof devServer . schema !== "undefined" ;
11
13
12
- // TODO only keep `getArguments` after drop webpack v4
14
+ let options = { } ;
13
15
14
- const options =
15
- typeof devServer . getArguments === "function"
16
- ? devServer . getArguments ( webpack )
17
- : // eslint-disable-next-line node/no-extraneous-require
18
- require ( "webpack-dev-server/bin/cli-flags" ) ;
16
+ if ( isNewDevServerCLIAPI ) {
17
+ if ( typeof webpack . cli . getArguments === "function" ) {
18
+ options = webpack . cli . getArguments ( devServer . schema ) ;
19
+ } else {
20
+ options = devServer . cli . getArguments ( ) ;
21
+ }
22
+ } else {
23
+ // eslint-disable-next-line node/no-extraneous-require
24
+ options = require ( "webpack-dev-server/bin/cli-flags" ) ;
25
+ }
19
26
20
27
// Old options format
21
28
// { devServer: [{...}, {}...] }
29
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
30
+ // @ts -ignore
22
31
if ( options . devServer ) {
32
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
33
+ // @ts -ignore
23
34
return options . devServer ;
24
35
}
25
36
@@ -149,25 +160,26 @@ class ServeCommand {
149
160
150
161
// eslint-disable-next-line @typescript-eslint/no-var-requires, node/no-extraneous-require
151
162
const devServer = require ( "webpack-dev-server" ) ;
163
+ const isNewDevServerCLIAPI = typeof devServer . schema !== "undefined" ;
152
164
153
- if ( typeof devServer . processArguments === "function" ) {
165
+ if ( isNewDevServerCLIAPI ) {
154
166
const args = devServerFlags . reduce ( ( accumulator , flag ) => {
155
167
accumulator [ flag . name ] = flag ;
156
-
157
168
return accumulator ;
158
169
} , { } ) ;
159
170
const values = Object . keys ( devServerOptions ) . reduce ( ( accumulator , name ) => {
160
171
const kebabName = cli . utils . toKebabCase ( name ) ;
161
-
162
172
if ( args [ kebabName ] ) {
163
173
accumulator [ kebabName ] = options [ name ] ;
164
174
}
165
-
166
175
return accumulator ;
167
176
} , { } ) ;
168
- const result = { ...compiler . options . devServer } ;
169
-
170
- const problems = devServer . processArguments ( cli . webpack , args , result , values ) ;
177
+ const result = Object . assign ( { } , compiler . options . devServer ) ;
178
+ const problems = (
179
+ typeof webpack . cli . processArguments === "function"
180
+ ? webpack . cli
181
+ : devServer . cli
182
+ ) . processArguments ( args , result , values ) ;
171
183
172
184
if ( problems ) {
173
185
const groupBy = ( xs , key ) => {
@@ -177,11 +189,11 @@ class ServeCommand {
177
189
return rv ;
178
190
} , { } ) ;
179
191
} ;
192
+
180
193
const problemsByPath = groupBy ( problems , "path" ) ;
181
194
182
195
for ( const path in problemsByPath ) {
183
196
const problems = problemsByPath [ path ] ;
184
-
185
197
problems . forEach ( ( problem ) => {
186
198
cli . logger . error (
187
199
`${ cli . utils . capitalizeFirstLetter (
0 commit comments