webpack-dev-server 3.1.6 → 3.1.7

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.
@@ -2,29 +2,59 @@
2
2
 
3
3
  'use strict';
4
4
 
5
- /* eslint global-require: off, import/order: off, no-console: off, import/no-extraneous-dependencies: off */
6
-
5
+ /* eslint-disable
6
+ import/order,
7
+ import/no-extraneous-dependencies,
8
+ global-require,
9
+ no-shadow,
10
+ no-console,
11
+ multiline-ternary,
12
+ arrow-parens,
13
+ array-bracket-spacing,
14
+ space-before-function-paren
15
+ */
7
16
  const debug = require('debug')('webpack-dev-server');
17
+
8
18
  const fs = require('fs');
9
19
  const net = require('net');
10
20
  const path = require('path');
11
- const importLocal = require('import-local');
12
- const open = require('opn');
21
+
13
22
  const portfinder = require('portfinder');
14
- const addDevServerEntrypoints = require('../lib/util/addDevServerEntrypoints');
15
- const createDomain = require('../lib/util/createDomain'); // eslint-disable-line
16
- const createLog = require('../lib/createLog');
23
+ const importLocal = require('import-local');
24
+
25
+ const yargs = require('yargs');
26
+ const webpack = require('webpack');
27
+
28
+ const options = require('./options');
29
+
30
+ const {
31
+ colors,
32
+ status,
33
+ version,
34
+ bonjour,
35
+ defaultTo
36
+ } = require('./utils');
37
+
38
+ const Server = require('../lib/Server');
39
+
40
+ const addEntries = require('../lib/utils/addEntries');
41
+ const createDomain = require('../lib/utils/createDomain');
42
+ const createLogger = require('../lib/utils/createLogger');
17
43
 
18
44
  let server;
19
45
 
20
- ['SIGINT', 'SIGTERM'].forEach((sig) => {
21
- process.on(sig, () => {
46
+ const signals = [ 'SIGINT', 'SIGTERM' ];
47
+
48
+ signals.forEach((signal) => {
49
+ process.on(signal, () => {
22
50
  if (server) {
23
51
  server.close(() => {
24
- process.exit(); // eslint-disable-line no-process-exit
52
+ // eslint-disable-next-line no-process-exit
53
+ process.exit();
25
54
  });
26
55
  } else {
27
- process.exit(); // eslint-disable-line no-process-exit
56
+ // eslint-disable-next-line no-process-exit
57
+ process.exit();
28
58
  }
29
59
  });
30
60
  });
@@ -32,287 +62,146 @@ let server;
32
62
  // Prefer the local installation of webpack-dev-server
33
63
  if (importLocal(__filename)) {
34
64
  debug('Using local install of webpack-dev-server');
65
+
35
66
  return;
36
67
  }
37
68
 
38
- const Server = require('../lib/Server');
39
- const webpack = require('webpack'); // eslint-disable-line
40
-
41
69
  try {
42
70
  require.resolve('webpack-cli');
43
- } catch (e) {
44
- console.error('The CLI moved into a separate package: webpack-cli.');
45
- console.error("Please install 'webpack-cli' in addition to webpack itself to use the CLI.");
46
- console.error('-> When using npm: npm install webpack-cli -D');
47
- console.error('-> When using yarn: yarn add webpack-cli -D');
48
- process.exitCode = 1;
49
- }
71
+ } catch (err) {
72
+ console.error('The CLI moved into a separate package: webpack-cli');
73
+ console.error('Please install \'webpack-cli\' in addition to webpack itself to use the CLI');
74
+ console.error('-> When using npm: npm i -D webpack-cli');
75
+ console.error('-> When using yarn: yarn add -D webpack-cli');
50
76
 
51
- function versionInfo() {
52
- return `webpack-dev-server ${require('../package.json').version}\n` +
53
- `webpack ${require('webpack/package.json').version}`;
54
- }
55
-
56
- function colorInfo(useColor, msg) {
57
- if (useColor) {
58
- // Make text blue and bold, so it *pops*
59
- return `\u001b[1m\u001b[34m${msg}\u001b[39m\u001b[22m`;
60
- }
61
- return msg;
62
- }
63
-
64
- function colorError(useColor, msg) {
65
- if (useColor) {
66
- // Make text red and bold, so it *pops*
67
- return `\u001b[1m\u001b[31m${msg}\u001b[39m\u001b[22m`;
68
- }
69
- return msg;
77
+ process.exitCode = 1;
70
78
  }
71
79
 
72
- // eslint-disable-next-line
73
- const defaultTo = (value, def) => value == null ? def : value;
74
-
75
- const yargs = require('yargs')
76
- .usage(`${versionInfo()}\nUsage: https://webpack.js.org/configuration/dev-server/`);
80
+ yargs.usage(
81
+ `${version()}\nUsage: https://webpack.js.org/configuration/dev-server/`
82
+ );
77
83
 
78
84
  require('webpack-cli/bin/config-yargs')(yargs);
79
-
80
85
  // It is important that this is done after the webpack yargs config,
81
86
  // so it overrides webpack's version info.
82
- yargs
83
- .version(versionInfo());
87
+ yargs.version(version());
88
+ yargs.options(options);
84
89
 
85
- const ADVANCED_GROUP = 'Advanced options:';
86
- const DISPLAY_GROUP = 'Stats options:';
87
- const SSL_GROUP = 'SSL options:';
88
- const CONNECTION_GROUP = 'Connection options:';
89
- const RESPONSE_GROUP = 'Response options:';
90
- const BASIC_GROUP = 'Basic options:';
90
+ const argv = yargs.argv;
91
91
 
92
+ const config = require('webpack-cli/bin/convert-argv')(yargs, argv, {
93
+ outputFilename: '/bundle.js'
94
+ });
92
95
  // Taken out of yargs because we must know if
93
96
  // it wasn't given by the user, in which case
94
97
  // we should use portfinder.
95
98
  const DEFAULT_PORT = 8080;
96
99
 
97
- yargs.options({
98
- bonjour: {
99
- type: 'boolean',
100
- describe: 'Broadcasts the server via ZeroConf networking on start'
101
- },
102
- lazy: {
103
- type: 'boolean',
104
- describe: 'Lazy'
105
- },
106
- inline: {
107
- type: 'boolean',
108
- default: true,
109
- describe: 'Inline mode (set to false to disable including client scripts like livereload)'
110
- },
111
- progress: {
112
- type: 'boolean',
113
- describe: 'Print compilation progress in percentage',
114
- group: BASIC_GROUP
115
- },
116
- 'hot-only': {
117
- type: 'boolean',
118
- describe: 'Do not refresh page if HMR fails',
119
- group: ADVANCED_GROUP
120
- },
121
- stdin: {
122
- type: 'boolean',
123
- describe: 'close when stdin ends'
124
- },
125
- open: {
126
- type: 'string',
127
- describe: 'Open the default browser, or optionally specify a browser name'
128
- },
129
- useLocalIp: {
130
- type: 'boolean',
131
- describe: 'Open default browser with local IP'
132
- },
133
- 'open-page': {
134
- type: 'string',
135
- describe: 'Open default browser with the specified page',
136
- requiresArg: true
137
- },
138
- color: {
139
- type: 'boolean',
140
- alias: 'colors',
141
- default: function supportsColor() {
142
- return require('supports-color');
143
- },
144
- group: DISPLAY_GROUP,
145
- describe: 'Enables/Disables colors on the console'
146
- },
147
- info: {
148
- type: 'boolean',
149
- group: DISPLAY_GROUP,
150
- default: true,
151
- describe: 'Info'
152
- },
153
- quiet: {
154
- type: 'boolean',
155
- group: DISPLAY_GROUP,
156
- describe: 'Quiet'
157
- },
158
- 'client-log-level': {
159
- type: 'string',
160
- group: DISPLAY_GROUP,
161
- default: 'info',
162
- describe: 'Log level in the browser (info, warning, error or none)'
163
- },
164
- https: {
165
- type: 'boolean',
166
- group: SSL_GROUP,
167
- describe: 'HTTPS'
168
- },
169
- key: {
170
- type: 'string',
171
- describe: 'Path to a SSL key.',
172
- group: SSL_GROUP
173
- },
174
- cert: {
175
- type: 'string',
176
- describe: 'Path to a SSL certificate.',
177
- group: SSL_GROUP
178
- },
179
- cacert: {
180
- type: 'string',
181
- describe: 'Path to a SSL CA certificate.',
182
- group: SSL_GROUP
183
- },
184
- pfx: {
185
- type: 'string',
186
- describe: 'Path to a SSL pfx file.',
187
- group: SSL_GROUP
188
- },
189
- 'pfx-passphrase': {
190
- type: 'string',
191
- describe: 'Passphrase for pfx file.',
192
- group: SSL_GROUP
193
- },
194
- 'content-base': {
195
- type: 'string',
196
- describe: 'A directory or URL to serve HTML content from.',
197
- group: RESPONSE_GROUP
198
- },
199
- 'watch-content-base': {
200
- type: 'boolean',
201
- describe: 'Enable live-reloading of the content-base.',
202
- group: RESPONSE_GROUP
203
- },
204
- 'history-api-fallback': {
205
- type: 'boolean',
206
- describe: 'Fallback to /index.html for Single Page Applications.',
207
- group: RESPONSE_GROUP
208
- },
209
- compress: {
210
- type: 'boolean',
211
- describe: 'Enable gzip compression',
212
- group: RESPONSE_GROUP
213
- },
214
- port: {
215
- describe: 'The port',
216
- group: CONNECTION_GROUP
217
- },
218
- 'disable-host-check': {
219
- type: 'boolean',
220
- describe: 'Will not check the host',
221
- group: CONNECTION_GROUP
222
- },
223
- socket: {
224
- type: 'String',
225
- describe: 'Socket to listen',
226
- group: CONNECTION_GROUP
227
- },
228
- public: {
229
- type: 'string',
230
- describe: 'The public hostname/ip address of the server',
231
- group: CONNECTION_GROUP
232
- },
233
- host: {
234
- type: 'string',
235
- default: 'localhost',
236
- describe: 'The hostname/ip address the server will bind to',
237
- group: CONNECTION_GROUP
238
- },
239
- 'allowed-hosts': {
240
- type: 'string',
241
- describe: 'A comma-delimited string of hosts that are allowed to access the dev server',
242
- group: CONNECTION_GROUP
243
- }
244
- });
245
-
246
- const argv = yargs.argv;
247
- const wpOpt = require('webpack-cli/bin/convert-argv')(yargs, argv, {
248
- outputFilename: '/bundle.js'
249
- });
250
-
251
- function processOptions(webpackOptions) {
252
- // process Promise
253
- if (typeof webpackOptions.then === 'function') {
254
- webpackOptions.then(processOptions).catch((err) => {
100
+ function processOptions (config) {
101
+ // processOptions {Promise}
102
+ if (typeof config.then === 'function') {
103
+ config.then(processOptions).catch((err) => {
255
104
  console.error(err.stack || err);
256
- process.exit(); // eslint-disable-line
105
+ // eslint-disable-next-line no-process-exit
106
+ process.exit();
257
107
  });
108
+
258
109
  return;
259
110
  }
260
111
 
261
- const firstWpOpt = Array.isArray(webpackOptions) ? webpackOptions[0] : webpackOptions;
112
+ const firstWpOpt = Array.isArray(config)
113
+ ? config[0]
114
+ : config;
262
115
 
263
- const options = webpackOptions.devServer || firstWpOpt.devServer || {};
116
+ const options = config.devServer || firstWpOpt.devServer || {};
264
117
 
265
- if (argv.bonjour) { options.bonjour = true; }
118
+ if (argv.bonjour) {
119
+ options.bonjour = true;
120
+ }
266
121
 
267
- if (argv.host !== 'localhost' || !options.host) { options.host = argv.host; }
122
+ if (argv.host !== 'localhost' || !options.host) {
123
+ options.host = argv.host;
124
+ }
268
125
 
269
- if (argv['allowed-hosts']) { options.allowedHosts = argv['allowed-hosts'].split(','); }
126
+ if (argv['allowed-hosts']) {
127
+ options.allowedHosts = argv['allowed-hosts'].split(',');
128
+ }
270
129
 
271
- if (argv.public) { options.public = argv.public; }
130
+ if (argv.public) {
131
+ options.public = argv.public;
132
+ }
272
133
 
273
- if (argv.socket) { options.socket = argv.socket; }
134
+ if (argv.socket) {
135
+ options.socket = argv.socket;
136
+ }
274
137
 
275
- if (argv.progress) { options.progress = argv.progress; }
138
+ if (argv.progress) {
139
+ options.progress = argv.progress;
140
+ }
276
141
 
277
142
  if (!options.publicPath) {
278
143
  // eslint-disable-next-line
279
144
  options.publicPath = firstWpOpt.output && firstWpOpt.output.publicPath || '';
280
- if (!/^(https?:)?\/\//.test(options.publicPath) && options.publicPath[0] !== '/') {
145
+
146
+ if (
147
+ !/^(https?:)?\/\//.test(options.publicPath) &&
148
+ options.publicPath[0] !== '/'
149
+ ) {
281
150
  options.publicPath = `/${options.publicPath}`;
282
151
  }
283
152
  }
284
153
 
285
- if (!options.filename) { options.filename = firstWpOpt.output && firstWpOpt.output.filename; }
154
+ if (!options.filename) {
155
+ options.filename = firstWpOpt.output && firstWpOpt.output.filename;
156
+ }
286
157
 
287
- if (!options.watchOptions) { options.watchOptions = firstWpOpt.watchOptions; }
158
+ if (!options.watchOptions) {
159
+ options.watchOptions = firstWpOpt.watchOptions;
160
+ }
288
161
 
289
162
  if (argv.stdin) {
290
163
  process.stdin.on('end', () => {
291
- process.exit(0); // eslint-disable-line no-process-exit
164
+ // eslint-disable-next-line no-process-exit
165
+ process.exit(0);
292
166
  });
167
+
293
168
  process.stdin.resume();
294
169
  }
295
170
 
296
- if (!options.hot) { options.hot = argv.hot; }
171
+ if (!options.hot) {
172
+ options.hot = argv.hot;
173
+ }
297
174
 
298
- if (!options.hotOnly) { options.hotOnly = argv['hot-only']; }
175
+ if (!options.hotOnly) {
176
+ options.hotOnly = argv['hot-only'];
177
+ }
299
178
 
300
- if (!options.clientLogLevel) { options.clientLogLevel = argv['client-log-level']; }
179
+ if (!options.clientLogLevel) {
180
+ options.clientLogLevel = argv['client-log-level'];
181
+ }
301
182
 
302
183
  // eslint-disable-next-line
303
184
  if (options.contentBase === undefined) {
304
185
  if (argv['content-base']) {
305
186
  options.contentBase = argv['content-base'];
187
+
306
188
  if (Array.isArray(options.contentBase)) {
307
- options.contentBase = options.contentBase.map(val => path.resolve(val));
308
- } else if (/^[0-9]$/.test(options.contentBase)) { options.contentBase = +options.contentBase; } else if (!/^(https?:)?\/\//.test(options.contentBase)) { options.contentBase = path.resolve(options.contentBase); }
309
- // It is possible to disable the contentBase by using `--no-content-base`, which results in arg["content-base"] = false
189
+ options.contentBase = options.contentBase.map((p) => path.resolve(p));
190
+ } else if (/^[0-9]$/.test(options.contentBase)) {
191
+ options.contentBase = +options.contentBase;
192
+ } else if (!/^(https?:)?\/\//.test(options.contentBase)) {
193
+ options.contentBase = path.resolve(options.contentBase);
194
+ }
195
+ // It is possible to disable the contentBase by using
196
+ // `--no-content-base`, which results in arg["content-base"] = false
310
197
  } else if (argv['content-base'] === false) {
311
198
  options.contentBase = false;
312
199
  }
313
200
  }
314
201
 
315
- if (argv['watch-content-base']) { options.watchContentBase = true; }
202
+ if (argv['watch-content-base']) {
203
+ options.watchContentBase = true;
204
+ }
316
205
 
317
206
  if (!options.stats) {
318
207
  options.stats = {
@@ -321,35 +210,76 @@ function processOptions(webpackOptions) {
321
210
  };
322
211
  }
323
212
 
324
- if (typeof options.stats === 'object' && typeof options.stats.colors === 'undefined') {
325
- options.stats = Object.assign({}, options.stats, { colors: argv.color });
213
+ if (
214
+ typeof options.stats === 'object' &&
215
+ typeof options.stats.colors === 'undefined'
216
+ ) {
217
+ options.stats = Object.assign(
218
+ {},
219
+ options.stats,
220
+ { colors: argv.color }
221
+ );
326
222
  }
327
223
 
328
- if (argv.lazy) { options.lazy = true; }
224
+ if (argv.lazy) {
225
+ options.lazy = true;
226
+ }
329
227
 
330
- if (!argv.info) { options.noInfo = true; }
228
+ if (!argv.info) {
229
+ options.noInfo = true;
230
+ }
331
231
 
332
- if (argv.quiet) { options.quiet = true; }
232
+ if (argv.quiet) {
233
+ options.quiet = true;
234
+ }
333
235
 
334
- if (argv.https) { options.https = true; }
236
+ if (argv.https) {
237
+ options.https = true;
238
+ }
335
239
 
336
- if (argv.cert) { options.cert = fs.readFileSync(path.resolve(argv.cert)); }
240
+ if (argv.cert) {
241
+ options.cert = fs.readFileSync(
242
+ path.resolve(argv.cert)
243
+ );
244
+ }
337
245
 
338
- if (argv.key) { options.key = fs.readFileSync(path.resolve(argv.key)); }
246
+ if (argv.key) {
247
+ options.key = fs.readFileSync(
248
+ path.resolve(argv.key)
249
+ );
250
+ }
339
251
 
340
- if (argv.cacert) { options.ca = fs.readFileSync(path.resolve(argv.cacert)); }
252
+ if (argv.cacert) {
253
+ options.ca = fs.readFileSync(
254
+ path.resolve(argv.cacert)
255
+ );
256
+ }
341
257
 
342
- if (argv.pfx) { options.pfx = fs.readFileSync(path.resolve(argv.pfx)); }
258
+ if (argv.pfx) {
259
+ options.pfx = fs.readFileSync(
260
+ path.resolve(argv.pfx)
261
+ );
262
+ }
343
263
 
344
- if (argv['pfx-passphrase']) { options.pfxPassphrase = argv['pfx-passphrase']; }
264
+ if (argv['pfx-passphrase']) {
265
+ options.pfxPassphrase = argv['pfx-passphrase'];
266
+ }
345
267
 
346
- if (argv.inline === false) { options.inline = false; }
268
+ if (argv.inline === false) {
269
+ options.inline = false;
270
+ }
347
271
 
348
- if (argv['history-api-fallback']) { options.historyApiFallback = true; }
272
+ if (argv['history-api-fallback']) {
273
+ options.historyApiFallback = true;
274
+ }
349
275
 
350
- if (argv.compress) { options.compress = true; }
276
+ if (argv.compress) {
277
+ options.compress = true;
278
+ }
351
279
 
352
- if (argv['disable-host-check']) { options.disableHostCheck = true; }
280
+ if (argv['disable-host-check']) {
281
+ options.disableHostCheck = true;
282
+ }
353
283
 
354
284
  if (argv['open-page']) {
355
285
  options.open = true;
@@ -360,42 +290,57 @@ function processOptions(webpackOptions) {
360
290
  options.open = argv.open !== '' ? argv.open : true;
361
291
  }
362
292
 
363
- if (options.open && !options.openPage) { options.openPage = ''; }
364
-
365
- if (argv.useLocalIp) { options.useLocalIp = true; }
293
+ if (options.open && !options.openPage) {
294
+ options.openPage = '';
295
+ }
366
296
 
297
+ if (argv.useLocalIp) {
298
+ options.useLocalIp = true;
299
+ }
367
300
  // Kind of weird, but ensures prior behavior isn't broken in cases
368
301
  // that wouldn't throw errors. E.g. both argv.port and options.port
369
302
  // were specified, but since argv.port is 8080, options.port will be
370
303
  // tried first instead.
371
- options.port = argv.port === DEFAULT_PORT ? defaultTo(options.port, argv.port) : defaultTo(argv.port, options.port);
304
+ options.port = argv.port === DEFAULT_PORT
305
+ ? defaultTo(options.port, argv.port)
306
+ : defaultTo(argv.port, options.port);
372
307
 
373
308
  if (options.port != null) {
374
- startDevServer(webpackOptions, options);
309
+ startDevServer(config, options);
310
+
375
311
  return;
376
312
  }
377
313
 
378
314
  portfinder.basePort = DEFAULT_PORT;
315
+
379
316
  portfinder.getPort((err, port) => {
380
- if (err) throw err;
317
+ if (err) {
318
+ throw err;
319
+ }
320
+
381
321
  options.port = port;
382
- startDevServer(webpackOptions, options);
322
+
323
+ startDevServer(config, options);
383
324
  });
384
325
  }
385
326
 
386
- function startDevServer(webpackOptions, options) {
387
- const log = createLog(options);
388
- addDevServerEntrypoints(webpackOptions, options);
327
+ function startDevServer(config, options) {
328
+ const log = createLogger(options);
329
+
330
+ addEntries(config, options);
389
331
 
390
332
  let compiler;
333
+
391
334
  try {
392
- compiler = webpack(webpackOptions);
393
- } catch (e) {
394
- if (e instanceof webpack.WebpackOptionsValidationError) {
395
- log.error(colorError(options.stats.colors, e.message));
396
- process.exit(1); // eslint-disable-line
335
+ compiler = webpack(config);
336
+ } catch (err) {
337
+ if (err instanceof webpack.WebpackOptionsValidationError) {
338
+ log.error(colors.error(options.stats.colors, err.message));
339
+ // eslint-disable-next-line no-process-exit
340
+ process.exit(1);
397
341
  }
398
- throw e;
342
+
343
+ throw err;
399
344
  }
400
345
 
401
346
  if (options.progress) {
@@ -408,101 +353,72 @@ function startDevServer(webpackOptions, options) {
408
353
 
409
354
  try {
410
355
  server = new Server(compiler, options, log);
411
- } catch (e) {
412
- const OptionsValidationError = require('../lib/OptionsValidationError');
413
- if (e instanceof OptionsValidationError) {
414
- log.error(colorError(options.stats.colors, e.message));
415
- process.exit(1); // eslint-disable-line
356
+ } catch (err) {
357
+ if (err.name === 'ValidationError') {
358
+ log.error(colors.error(options.stats.colors, err.message));
359
+ // eslint-disable-next-line no-process-exit
360
+ process.exit(1);
416
361
  }
417
- throw e;
362
+
363
+ throw err;
418
364
  }
419
365
 
420
366
  if (options.socket) {
421
367
  server.listeningApp.on('error', (e) => {
422
368
  if (e.code === 'EADDRINUSE') {
423
369
  const clientSocket = new net.Socket();
424
- clientSocket.on('error', (clientError) => {
425
- if (clientError.code === 'ECONNREFUSED') {
370
+
371
+ clientSocket.on('error', (err) => {
372
+ if (err.code === 'ECONNREFUSED') {
426
373
  // No other server listening on this socket so it can be safely removed
427
374
  fs.unlinkSync(options.socket);
428
- server.listen(options.socket, options.host, (err) => {
429
- if (err) throw err;
375
+
376
+ server.listen(options.socket, options.host, (error) => {
377
+ if (error) {
378
+ throw error;
379
+ }
430
380
  });
431
381
  }
432
382
  });
383
+
433
384
  clientSocket.connect({ path: options.socket }, () => {
434
385
  throw new Error('This socket is already used');
435
386
  });
436
387
  }
437
388
  });
389
+
438
390
  server.listen(options.socket, options.host, (err) => {
439
- if (err) throw err;
391
+ if (err) {
392
+ throw err;
393
+ }
440
394
  // chmod 666 (rw rw rw)
441
395
  const READ_WRITE = 438;
442
- fs.chmod(options.socket, READ_WRITE, (fsError) => {
443
- if (fsError) throw fsError;
396
+
397
+ fs.chmod(options.socket, READ_WRITE, (err) => {
398
+ if (err) {
399
+ throw err;
400
+ }
444
401
 
445
402
  const uri = createDomain(options, server.listeningApp) + suffix;
446
- reportReadiness(uri, options, log);
403
+
404
+ status(uri, options, log, argv.color);
447
405
  });
448
406
  });
449
407
  } else {
450
408
  server.listen(options.port, options.host, (err) => {
451
- if (err) throw err;
452
- if (options.bonjour) broadcastZeroconf(options);
453
-
454
- const uri = createDomain(options, server.listeningApp) + suffix;
455
- reportReadiness(uri, options, log);
456
- });
457
- }
458
- }
459
-
460
- function reportReadiness(uri, options, log) {
461
- const useColor = argv.color;
462
- const contentBase = Array.isArray(options.contentBase) ? options.contentBase.join(', ') : options.contentBase;
463
-
464
- if (options.socket) {
465
- log.info(`Listening to socket at ${colorInfo(useColor, options.socket)}`);
466
- } else {
467
- log.info(`Project is running at ${colorInfo(useColor, uri)}`);
468
- }
469
-
470
- log.info(`webpack output is served from ${colorInfo(useColor, options.publicPath)}`);
471
-
472
- if (contentBase) { log.info(`Content not from webpack is served from ${colorInfo(useColor, contentBase)}`); }
473
-
474
- if (options.historyApiFallback) { log.info(`404s will fallback to ${colorInfo(useColor, options.historyApiFallback.index || '/index.html')}`); }
475
-
476
- if (options.bonjour) { log.info('Broadcasting "http" with subtype of "webpack" via ZeroConf DNS (Bonjour)'); }
409
+ if (err) {
410
+ throw err;
411
+ }
477
412
 
478
- if (options.open) {
479
- let openOptions = {};
480
- let openMessage = 'Unable to open browser';
413
+ if (options.bonjour) {
414
+ bonjour(options);
415
+ }
481
416
 
482
- if (typeof options.open === 'string') {
483
- openOptions = { app: options.open };
484
- openMessage += `: ${options.open}`;
485
- }
417
+ const uri = createDomain(options, server.listeningApp) + suffix;
486
418
 
487
- open(uri + (options.openPage || ''), openOptions).catch(() => {
488
- log.warn(`${openMessage}. If you are running in a headless environment, please do not use the open flag.`);
419
+ status(uri, options, log, argv.color);
489
420
  });
490
421
  }
491
422
  }
492
423
 
493
- function broadcastZeroconf(options) {
494
- const bonjour = require('bonjour')();
495
- bonjour.publish({
496
- name: 'Webpack Dev Server',
497
- port: options.port,
498
- type: 'http',
499
- subtypes: ['webpack']
500
- });
501
- process.on('exit', () => {
502
- bonjour.unpublishAll(() => {
503
- bonjour.destroy();
504
- });
505
- });
506
- }
507
-
508
- processOptions(wpOpt);
424
+ processOptions(config);