Skip to content

Commit f235ddc

Browse files
authored
Don't use PWD as a default for --content-base in yargs (#599)
The default value according to --help is the PWD. This is not always true. If `contentBase` is set in the webpack config, this default value is ignored.
1 parent 34093ef commit f235ddc

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

bin/webpack-dev-server.js

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ yargs.options({
9090
},
9191
"content-base": {
9292
type: "string",
93-
default: process.cwd(),
9493
describe: "A directory or URL to serve HTML content from.",
9594
group: RESPONSE_GROUP
9695
},
@@ -184,16 +183,21 @@ function processOptions(wpOpt) {
184183
if(!options.clientLogLevel)
185184
options.clientLogLevel = argv["client-log-level"];
186185

187-
if(!options.contentBase && argv["content-base"]) {
188-
options.contentBase = argv["content-base"];
189-
if(/^[0-9]$/.test(options.contentBase))
190-
options.contentBase = +options.contentBase;
191-
else if(!/^(https?:)?\/\//.test(options.contentBase))
192-
options.contentBase = path.resolve(options.contentBase);
193-
} else if(argv["content-base-target"]) {
194-
options.contentBase = {
195-
target: argv["content-base-target"]
196-
};
186+
if(!options.contentBase) {
187+
if(argv["content-base"]) {
188+
options.contentBase = argv["content-base"];
189+
if(/^[0-9]$/.test(options.contentBase))
190+
options.contentBase = +options.contentBase;
191+
else if(!/^(https?:)?\/\//.test(options.contentBase))
192+
options.contentBase = path.resolve(options.contentBase);
193+
} else if(argv["content-base-target"]) {
194+
options.contentBase = {
195+
target: argv["content-base-target"]
196+
};
197+
// It is possible to disable the contentBase by using `--no-content-base`, which results in arg["content-base"] = false
198+
} else if(argv["content-base"] !== false) {
199+
options.contentBase = process.cwd();
200+
}
197201
}
198202

199203
if(!options.stats) {

0 commit comments

Comments
 (0)