@@ -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 {
@@ -64,6 +65,10 @@ const BASIC_GROUP = "Basic options:";
64
65
const DEFAULT_PORT = 8080 ;
65
66
66
67
yargs . options ( {
68
+ "bonjour" : {
69
+ type : "boolean" ,
70
+ describe : "Broadcasts the server via ZeroConf networking on start"
71
+ } ,
67
72
"lazy" : {
68
73
type : "boolean" ,
69
74
describe : "Lazy"
@@ -214,6 +219,9 @@ function processOptions(wpOpt) {
214
219
215
220
const options = wpOpt . devServer || firstWpOpt . devServer || { } ;
216
221
222
+ if ( argv . bonjour )
223
+ options . bonjour = true ;
224
+
217
225
if ( argv . host !== "localhost" || ! options . host )
218
226
options . host = argv . host ;
219
227
@@ -410,6 +418,7 @@ function startDevServer(wpOpt, options) {
410
418
} else {
411
419
server . listen ( options . port , options . host , function ( err ) {
412
420
if ( err ) throw err ;
421
+ if ( options . bonjour ) broadcastZeroconf ( options ) ;
413
422
reportReadiness ( uri , options ) ;
414
423
} ) ;
415
424
}
@@ -434,6 +443,22 @@ function reportReadiness(uri, options) {
434
443
console . log ( "Unable to open browser. If you are running in a headless environment, please do not use the open flag." ) ;
435
444
} ) ;
436
445
}
446
+ if ( options . bonjour )
447
+ console . log ( "Broadcasting \"http\" with subtype of \"webpack\" via ZeroConf DNS (Bonjour)" ) ;
448
+ }
449
+
450
+ function broadcastZeroconf ( options ) {
451
+ bonjour . publish ( {
452
+ name : "Webpack Dev Server" ,
453
+ port : options . port ,
454
+ type : "http" ,
455
+ subtypes : [ "webpack" ]
456
+ } ) ;
457
+ process . on ( "exit" , function ( ) {
458
+ bonjour . unpublishAll ( function ( ) {
459
+ bonjour . destroy ( ) ;
460
+ } ) ;
461
+ } ) ;
437
462
}
438
463
439
464
processOptions ( wpOpt ) ;
0 commit comments