@@ -14,12 +14,12 @@ function createConfig(config, argv, { port }) {
1414 options . bonjour = true ;
1515 }
1616
17- if ( argv . host !== 'localhost' || ! options . host ) {
17+ if ( argv . host && ( argv . host !== 'localhost' || ! options . host ) ) {
1818 options . host = argv . host ;
1919 }
2020
21- if ( argv [ 'allowed-hosts' ] ) {
22- options . allowedHosts = argv [ 'allowed-hosts' ] . split ( ',' ) ;
21+ if ( argv . allowedHosts ) {
22+ options . allowedHosts = argv . allowedHosts . split ( ',' ) ;
2323 }
2424
2525 if ( argv . public ) {
@@ -47,11 +47,11 @@ function createConfig(config, argv, { port }) {
4747 }
4848 }
4949
50- if ( ! options . filename ) {
50+ if ( ! options . filename && firstWpOpt . output && firstWpOpt . output . filename ) {
5151 options . filename = firstWpOpt . output && firstWpOpt . output . filename ;
5252 }
5353
54- if ( ! options . watchOptions ) {
54+ if ( ! options . watchOptions && firstWpOpt . watchOptions ) {
5555 options . watchOptions = firstWpOpt . watchOptions ;
5656 }
5757
@@ -64,38 +64,42 @@ function createConfig(config, argv, { port }) {
6464 process . stdin . resume ( ) ;
6565 }
6666
67+ // TODO https://github.com/webpack/webpack-dev-server/issues/616 (v4)
68+ // We should prefer CLI arg under config, now we always prefer `hot` from `devServer`
6769 if ( ! options . hot ) {
6870 options . hot = argv . hot ;
6971 }
7072
73+ // TODO https://github.com/webpack/webpack-dev-server/issues/616 (v4)
74+ // We should prefer CLI arg under config, now we always prefer `hotOnly` from `devServer`
7175 if ( ! options . hotOnly ) {
72- options . hotOnly = argv [ 'hot-only' ] ;
76+ options . hotOnly = argv . hotOnly ;
7377 }
7478
75- if ( ! options . clientLogLevel ) {
76- options . clientLogLevel = argv [ 'client-log-level' ] ;
79+ // TODO https://github.com/webpack/webpack-dev-server/issues/616 (v4)
80+ // We should prefer CLI arg under config, now we always prefer `clientLogLevel` from `devServer`
81+ if ( ! options . clientLogLevel && argv . clientLogLevel ) {
82+ options . clientLogLevel = argv . clientLogLevel ;
7783 }
7884
79- // eslint-disable-next-line
80- if ( options . contentBase === undefined ) {
81- if ( argv [ 'content-base' ] ) {
82- options . contentBase = argv [ 'content-base' ] ;
85+ if ( argv . contentBase ) {
86+ options . contentBase = argv . contentBase ;
8387
84- if ( Array . isArray ( options . contentBase ) ) {
85- options . contentBase = options . contentBase . map ( ( p ) => path . resolve ( p ) ) ;
86- } else if ( / ^ [ 0 - 9 ] $ / . test ( options . contentBase ) ) {
87- options . contentBase = + options . contentBase ;
88- } else if ( ! / ^ ( h t t p s ? : ) ? \/ \/ / . test ( options . contentBase ) ) {
89- options . contentBase = path . resolve ( options . contentBase ) ;
90- }
91- // It is possible to disable the contentBase by using
92- // `--no-content-base`, which results in arg["content-base"] = false
93- } else if ( argv [ 'content-base' ] === false ) {
94- options . contentBase = false ;
88+ if ( Array . isArray ( options . contentBase ) ) {
89+ options . contentBase = options . contentBase . map ( ( p ) => path . resolve ( p ) ) ;
90+ } else if ( / ^ [ 0 - 9 ] $ / . test ( options . contentBase ) ) {
91+ options . contentBase = + options . contentBase ;
92+ } else if ( ! / ^ ( h t t p s ? : ) ? \/ \/ / . test ( options . contentBase ) ) {
93+ options . contentBase = path . resolve ( options . contentBase ) ;
9594 }
95+ // It is possible to disable the contentBase by using
96+ // `--no-content-base`, which results in arg["content-base"] = false
97+ } else if ( argv . contentBase === false ) {
98+ // TODO doesn't work need fix, `false` in this case is string
99+ options . contentBase = false ;
96100 }
97101
98- if ( argv [ 'watch-content-base' ] ) {
102+ if ( argv . watchContentBase ) {
99103 options . watchContentBase = true ;
100104 }
101105
@@ -108,7 +112,8 @@ function createConfig(config, argv, { port }) {
108112
109113 if (
110114 typeof options . stats === 'object' &&
111- typeof options . stats . colors === 'undefined'
115+ typeof options . stats . colors === 'undefined' &&
116+ argv . color
112117 ) {
113118 options . stats = Object . assign ( { } , options . stats , { colors : argv . color } ) ;
114119 }
@@ -117,10 +122,12 @@ function createConfig(config, argv, { port }) {
117122 options . lazy = true ;
118123 }
119124
125+ // TODO remove in `v4`
120126 if ( ! argv . info ) {
121127 options . noInfo = true ;
122128 }
123129
130+ // TODO remove in `v4`
124131 if ( argv . quiet ) {
125132 options . quiet = true ;
126133 }
@@ -129,29 +136,29 @@ function createConfig(config, argv, { port }) {
129136 options . https = true ;
130137 }
131138
132- if ( argv [ 'pfx-passphrase' ] ) {
133- options . pfxPassphrase = argv [ 'pfx-passphrase' ] ;
139+ if ( argv . pfxPassphrase ) {
140+ options . pfxPassphrase = argv . pfxPassphrase ;
134141 }
135142
136143 if ( argv . inline === false ) {
137144 options . inline = false ;
138145 }
139146
140- if ( argv [ 'history-api-fallback' ] ) {
147+ if ( argv . historyApiFallback ) {
141148 options . historyApiFallback = true ;
142149 }
143150
144151 if ( argv . compress ) {
145152 options . compress = true ;
146153 }
147154
148- if ( argv [ 'disable-host-check' ] ) {
155+ if ( argv . disableHostCheck ) {
149156 options . disableHostCheck = true ;
150157 }
151158
152- if ( argv [ 'open-page' ] ) {
159+ if ( argv . openPage ) {
153160 options . open = true ;
154- options . openPage = argv [ 'open-page' ] ;
161+ options . openPage = argv . openPage ;
155162 }
156163
157164 if ( typeof argv . open !== 'undefined' ) {
0 commit comments