|
196 | 196 | "Controls the output of lifecycle messaging e.g. Started watching files... (verbose, info, none)"
|
197 | 197 | }
|
198 | 198 | });
|
199 |
| - |
200 |
| - if (yargs.argv._.length === 0) { |
201 |
| - yargs.showHelp(); |
202 |
| - return; |
203 |
| - } |
204 |
| - |
205 | 199 | // yargs will terminate the process early when the user uses help or version.
|
206 | 200 | // This causes large help outputs to be cut short (https://github.com/nodejs/node/wiki/API-changes-between-v0.10-and-v4#process).
|
207 | 201 | // To prevent this we use the yargs.parse API and exit the process normally
|
|
465 | 459 | if (err) {
|
466 | 460 | lastHash = null;
|
467 | 461 | console.error(err.stack || err);
|
468 |
| - if (err.details) console.error(err.details); |
469 |
| - process.exit(1); // eslint-disable-line |
| 462 | + if (err.details) { |
| 463 | + console.error(err.details); |
| 464 | + } |
| 465 | + process.exit(1); |
470 | 466 | }
|
| 467 | + |
471 | 468 | if (outputOptions.json) {
|
472 | 469 | stdout.write(
|
473 | 470 | JSON.stringify(stats.toJson(outputOptions), null, 2) + "\n"
|
|
477 | 474 | var statsString = stats.toString(outputOptions);
|
478 | 475 | if (statsString) stdout.write(statsString + "\n");
|
479 | 476 | }
|
| 477 | + |
480 | 478 | if (!options.watch && stats.hasErrors()) {
|
481 | 479 | process.exitCode = 2;
|
| 480 | + |
| 481 | + const fs = require("fs"); |
| 482 | + const context = stats.compilation.compiler.context; |
| 483 | + const configPath = context + "/webpack.config.js"; |
| 484 | + const configMissing = !fs.existsSync(configPath); |
| 485 | + if (yargs.argv._.length === 0 && configMissing) { |
| 486 | + yargs.showHelp("log"); |
| 487 | + } |
482 | 488 | }
|
483 | 489 | }
|
| 490 | + |
484 | 491 | if (firstOptions.watch || options.watch) {
|
485 | 492 | var watchOptions =
|
486 | 493 | firstOptions.watchOptions ||
|
|
496 | 503 | compiler.watch(watchOptions, compilerCallback);
|
497 | 504 | if (outputOptions.infoVerbosity !== "none")
|
498 | 505 | console.log("\nWebpack is watching the files…\n");
|
499 |
| - } else compiler.run(compilerCallback); |
| 506 | + } else { |
| 507 | + compiler.run(compilerCallback); |
| 508 | + } |
500 | 509 | }
|
501 | 510 |
|
502 | 511 | processOptions(options);
|
|
0 commit comments