webpack-dev-server 2.4.5 → 2.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,6 +8,7 @@ const net = require("net");
8
8
  const portfinder = require("portfinder");
9
9
  const addDevServerEntrypoints = require("../lib/util/addDevServerEntrypoints");
10
10
  const createDomain = require("../lib/util/createDomain");
11
+ const bonjour = require("bonjour")();
11
12
 
12
13
  // Local version replaces global one
13
14
  try {
@@ -39,6 +40,8 @@ function colorError(useColor, msg) {
39
40
  return msg;
40
41
  }
41
42
 
43
+ const defaultTo = (value, def) => value == null ? def : value;
44
+
42
45
  const yargs = require("yargs")
43
46
  .usage(`${versionInfo()
44
47
  }\nUsage: https://webpack.js.org/configuration/dev-server/`);
@@ -62,6 +65,10 @@ const BASIC_GROUP = "Basic options:";
62
65
  const DEFAULT_PORT = 8080;
63
66
 
64
67
  yargs.options({
68
+ "bonjour": {
69
+ type: "boolean",
70
+ describe: "Broadcasts the server via ZeroConf networking on start"
71
+ },
65
72
  "lazy": {
66
73
  type: "boolean",
67
74
  describe: "Lazy"
@@ -89,6 +96,15 @@ yargs.options({
89
96
  type: "boolean",
90
97
  describe: "Open default browser"
91
98
  },
99
+ "useLocalIp": {
100
+ type: "boolean",
101
+ describe: "Open default browser with local IP"
102
+ },
103
+ "open-page": {
104
+ type: "string",
105
+ describe: "Open default browser with the specified page",
106
+ requiresArg: true,
107
+ },
92
108
  "color": {
93
109
  type: "boolean",
94
110
  alias: "colors",
@@ -207,6 +223,9 @@ function processOptions(wpOpt) {
207
223
 
208
224
  const options = wpOpt.devServer || firstWpOpt.devServer || {};
209
225
 
226
+ if(argv.bonjour)
227
+ options.bonjour = true;
228
+
210
229
  if(argv.host !== "localhost" || !options.host)
211
230
  options.host = argv.host;
212
231
 
@@ -310,15 +329,20 @@ function processOptions(wpOpt) {
310
329
  if(argv["compress"])
311
330
  options.compress = true;
312
331
 
313
- if(argv["open"])
332
+ if(argv["open"] || argv["open-page"]) {
314
333
  options.open = true;
334
+ options.openPage = argv["open-page"] || "";
335
+ }
336
+
337
+ if(argv["useLocalIp"])
338
+ options.useLocalIp = true;
315
339
 
316
340
  // Kind of weird, but ensures prior behavior isn't broken in cases
317
341
  // that wouldn't throw errors. E.g. both argv.port and options.port
318
342
  // were specified, but since argv.port is 8080, options.port will be
319
343
  // tried first instead.
320
- options.port = argv.port === DEFAULT_PORT ? (options.port || argv.port) : (argv.port || options.port);
321
- if(options.port) {
344
+ options.port = argv.port === DEFAULT_PORT ? defaultTo(options.port, argv.port) : defaultTo(argv.port, options.port);
345
+ if(options.port != null) {
322
346
  startDevServer(wpOpt, options);
323
347
  return;
324
348
  }
@@ -401,6 +425,7 @@ function startDevServer(wpOpt, options) {
401
425
  } else {
402
426
  server.listen(options.port, options.host, function(err) {
403
427
  if(err) throw err;
428
+ if(options.bonjour) broadcastZeroconf(options);
404
429
  reportReadiness(uri, options);
405
430
  });
406
431
  }
@@ -421,10 +446,26 @@ function reportReadiness(uri, options) {
421
446
  if(options.historyApiFallback)
422
447
  console.log(`404s will fallback to ${colorInfo(useColor, options.historyApiFallback.index || "/index.html")}`);
423
448
  if(options.open) {
424
- open(uri).catch(function() {
449
+ open(uri + options.openPage).catch(function() {
425
450
  console.log("Unable to open browser. If you are running in a headless environment, please do not use the open flag.");
426
451
  });
427
452
  }
453
+ if(options.bonjour)
454
+ console.log("Broadcasting \"http\" with subtype of \"webpack\" via ZeroConf DNS (Bonjour)");
455
+ }
456
+
457
+ function broadcastZeroconf(options) {
458
+ bonjour.publish({
459
+ name: "Webpack Dev Server",
460
+ port: options.port,
461
+ type: "http",
462
+ subtypes: ["webpack"]
463
+ });
464
+ process.on("exit", function() {
465
+ bonjour.unpublishAll(function() {
466
+ bonjour.destroy();
467
+ });
468
+ });
428
469
  }
429
470
 
430
471
  processOptions(wpOpt);