webpack-dev-server 3.1.14 → 3.3.1

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.
package/lib/options.json CHANGED
@@ -1,6 +1,9 @@
1
1
  {
2
2
  "type": "object",
3
3
  "properties": {
4
+ "serveIndex": {
5
+ "type": "boolean"
6
+ },
4
7
  "hot": {
5
8
  "type": "boolean"
6
9
  },
@@ -14,7 +17,27 @@
14
17
  "type": "boolean"
15
18
  },
16
19
  "host": {
17
- "type": "string"
20
+ "anyOf": [
21
+ {
22
+ "type": "string"
23
+ },
24
+ {
25
+ "type": "null"
26
+ }
27
+ ]
28
+ },
29
+ "port": {
30
+ "anyOf": [
31
+ {
32
+ "type": "number"
33
+ },
34
+ {
35
+ "type": "string"
36
+ },
37
+ {
38
+ "type": "null"
39
+ }
40
+ ]
18
41
  },
19
42
  "allowedHosts": {
20
43
  "type": "array",
@@ -38,19 +61,12 @@
38
61
  "publicPath": {
39
62
  "type": "string"
40
63
  },
41
- "port": {
42
- "anyOf": [
43
- {
44
- "type": "number"
45
- },
46
- {
47
- "type": "string"
48
- }
49
- ]
50
- },
51
64
  "socket": {
52
65
  "type": "string"
53
66
  },
67
+ "sockPath": {
68
+ "type": "string"
69
+ },
54
70
  "watchOptions": {
55
71
  "type": "object"
56
72
  },
@@ -68,22 +84,10 @@
68
84
  "type": "object"
69
85
  },
70
86
  "logLevel": {
71
- "enum": [
72
- "info",
73
- "warn",
74
- "error",
75
- "debug",
76
- "trace",
77
- "silent"
78
- ]
87
+ "enum": ["info", "warn", "error", "debug", "trace", "silent"]
79
88
  },
80
89
  "clientLogLevel": {
81
- "enum": [
82
- "none",
83
- "info",
84
- "error",
85
- "warning"
86
- ]
90
+ "enum": ["none", "info", "error", "warning"]
87
91
  },
88
92
  "overlay": {
89
93
  "anyOf": [
@@ -171,12 +175,13 @@
171
175
  }
172
176
  ]
173
177
  },
178
+ "http2": {
179
+ "type": "boolean"
180
+ },
174
181
  "contentBase": {
175
182
  "anyOf": [
176
183
  {
177
- "enum": [
178
- false
179
- ]
184
+ "enum": [false]
180
185
  },
181
186
  {
182
187
  "type": "number"
@@ -273,13 +278,7 @@
273
278
  "type": "boolean"
274
279
  },
275
280
  {
276
- "enum": [
277
- "none",
278
- "errors-only",
279
- "minimal",
280
- "normal",
281
- "verbose"
282
- ]
281
+ "enum": ["none", "errors-only", "minimal", "normal", "verbose"]
283
282
  }
284
283
  ]
285
284
  },
@@ -292,6 +291,9 @@
292
291
  "noInfo": {
293
292
  "type": "boolean"
294
293
  },
294
+ "mimeTypes": {
295
+ "type": "object"
296
+ },
295
297
  "quiet": {
296
298
  "type": "boolean"
297
299
  },
@@ -321,6 +323,7 @@
321
323
  "filename": "should be {String|RegExp|Function} (https://webpack.js.org/configuration/dev-server/#devserver-filename-)",
322
324
  "port": "should be {String|Number} (https://webpack.js.org/configuration/dev-server/#devserver-port)",
323
325
  "socket": "should be {String} (https://webpack.js.org/configuration/dev-server/#devserver-socket)",
326
+ "sockPath": "should be {String} (https://webpack.js.org/configuration/dev-server/#devserver-sockPath)",
324
327
  "watchOptions": "should be {Object} (https://webpack.js.org/configuration/dev-server/#devserver-watchoptions)",
325
328
  "writeToDisk": "should be {Boolean|Function} (https://github.com/webpack/webpack-dev-middleware#writetodisk)",
326
329
  "headers": "should be {Object} (https://webpack.js.org/configuration/dev-server/#devserver-headers-)",
@@ -337,6 +340,7 @@
337
340
  "disableHostCheck": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserver-disablehostcheck)",
338
341
  "public": "should be {String} (https://webpack.js.org/configuration/dev-server/#devserver-public)",
339
342
  "https": "should be {Object|Boolean} (https://webpack.js.org/configuration/dev-server/#devserver-https)",
343
+ "http2": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserver-http2)",
340
344
  "contentBase": "should be {Array} (https://webpack.js.org/configuration/dev-server/#devserver-contentbase)",
341
345
  "watchContentBase": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserver-watchcontentbase)",
342
346
  "open": "should be {String|Boolean} (https://webpack.js.org/configuration/dev-server/#devserver-open)",
@@ -354,6 +358,7 @@
354
358
  "reporter": "should be {Function} (https://webpack.js.org/configuration/dev-server/#devserver-reporter)",
355
359
  "logTime": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserver-logtime)",
356
360
  "noInfo": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserver-noinfo-)",
361
+ "mimeTypes": "should be {Object} (https://webpack.js.org/configuration/dev-server/#devservermimetypes-)",
357
362
  "quiet": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserver-quiet-)",
358
363
  "serverSideRender": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserver-serversiderender)",
359
364
  "index": "should be {String} (https://webpack.js.org/configuration/dev-server/#devserver-index)",
@@ -1,26 +1,25 @@
1
1
  'use strict';
2
2
 
3
- /* eslint-disable
4
- no-shadow,
5
- no-param-reassign,
6
- array-bracket-spacing,
7
- space-before-function-paren
8
- */
3
+ const webpack = require('webpack');
9
4
  const createDomain = require('./createDomain');
10
5
 
11
- function addEntries (config, options, server) {
6
+ function addEntries(config, options, server) {
12
7
  if (options.inline !== false) {
13
8
  // we're stubbing the app in this method as it's static and doesn't require
14
9
  // a server to be supplied. createDomain requires an app with the
15
10
  // address() signature.
11
+
16
12
  const app = server || {
17
13
  address() {
18
14
  return { port: options.port };
19
- }
15
+ },
20
16
  };
21
17
 
22
18
  const domain = createDomain(options, app);
23
- const entries = [ `${require.resolve('../../client/')}?${domain}` ];
19
+ const sockPath = options.sockPath ? `&sockPath=${options.sockPath}` : '';
20
+ const entries = [
21
+ `${require.resolve('../../client/')}?${domain}${sockPath}`,
22
+ ];
24
23
 
25
24
  if (options.hotOnly) {
26
25
  entries.push(require.resolve('webpack/hot/only-dev-server'));
@@ -37,17 +36,39 @@ function addEntries (config, options, server) {
37
36
  const clone = {};
38
37
 
39
38
  Object.keys(entry).forEach((key) => {
40
- clone[key] = entries.concat(entry[key]);
39
+ // entry[key] should be a string here
40
+ clone[key] = prependEntry(entry[key]);
41
41
  });
42
42
 
43
43
  return clone;
44
44
  }
45
45
 
46
- return entries.concat(entry);
46
+ // in this case, entry is a string or an array.
47
+ // make sure that we do not add duplicates.
48
+ const entriesClone = entries.slice(0);
49
+ [].concat(entry).forEach((newEntry) => {
50
+ if (!entriesClone.includes(newEntry)) {
51
+ entriesClone.push(newEntry);
52
+ }
53
+ });
54
+ return entriesClone;
47
55
  };
48
56
 
57
+ // eslint-disable-next-line no-shadow
49
58
  [].concat(config).forEach((config) => {
50
59
  config.entry = prependEntry(config.entry || './src');
60
+
61
+ if (options.hot || options.hotOnly) {
62
+ config.plugins = config.plugins || [];
63
+ if (
64
+ !config.plugins.find(
65
+ (plugin) =>
66
+ plugin.constructor === webpack.HotModuleReplacementPlugin
67
+ )
68
+ ) {
69
+ config.plugins.push(new webpack.HotModuleReplacementPlugin());
70
+ }
71
+ }
51
72
  });
52
73
  }
53
74
  }
@@ -0,0 +1,22 @@
1
+ 'use strict';
2
+
3
+ const colors = {
4
+ info(useColor, msg) {
5
+ if (useColor) {
6
+ // Make text blue and bold, so it *pops*
7
+ return `\u001b[1m\u001b[34m${msg}\u001b[39m\u001b[22m`;
8
+ }
9
+
10
+ return msg;
11
+ },
12
+ error(useColor, msg) {
13
+ if (useColor) {
14
+ // Make text red and bold, so it *pops*
15
+ return `\u001b[1m\u001b[31m${msg}\u001b[39m\u001b[22m`;
16
+ }
17
+
18
+ return msg;
19
+ },
20
+ };
21
+
22
+ module.exports = colors;
@@ -1,11 +1,8 @@
1
1
  'use strict';
2
2
 
3
- /* eslint-disable
4
- space-before-function-paren
5
- */
6
3
  const selfsigned = require('selfsigned');
7
4
 
8
- function createCertificate (attrs) {
5
+ function createCertificate(attrs) {
9
6
  return selfsigned.generate(attrs, {
10
7
  algorithm: 'sha256',
11
8
  days: 30,
@@ -13,7 +10,7 @@ function createCertificate (attrs) {
13
10
  extensions: [
14
11
  {
15
12
  name: 'basicConstraints',
16
- cA: true
13
+ cA: true,
17
14
  },
18
15
  {
19
16
  name: 'keyUsage',
@@ -21,7 +18,7 @@ function createCertificate (attrs) {
21
18
  digitalSignature: true,
22
19
  nonRepudiation: true,
23
20
  keyEncipherment: true,
24
- dataEncipherment: true
21
+ dataEncipherment: true,
25
22
  },
26
23
  {
27
24
  name: 'subjectAltName',
@@ -29,36 +26,36 @@ function createCertificate (attrs) {
29
26
  {
30
27
  // type 2 is DNS
31
28
  type: 2,
32
- value: 'localhost'
29
+ value: 'localhost',
33
30
  },
34
31
  {
35
32
  type: 2,
36
- value: 'localhost.localdomain'
33
+ value: 'localhost.localdomain',
37
34
  },
38
35
  {
39
36
  type: 2,
40
- value: 'lvh.me'
37
+ value: 'lvh.me',
41
38
  },
42
39
  {
43
40
  type: 2,
44
- value: '*.lvh.me'
41
+ value: '*.lvh.me',
45
42
  },
46
43
  {
47
44
  type: 2,
48
- value: '[::1]'
45
+ value: '[::1]',
49
46
  },
50
47
  {
51
48
  // type 7 is IP
52
49
  type: 7,
53
- ip: '127.0.0.1'
50
+ ip: '127.0.0.1',
54
51
  },
55
52
  {
56
53
  type: 7,
57
- ip: 'fe80::1'
58
- }
59
- ]
60
- }
61
- ]
54
+ ip: 'fe80::1',
55
+ },
56
+ ],
57
+ },
58
+ ],
62
59
  });
63
60
  }
64
61
 
@@ -0,0 +1,208 @@
1
+ 'use strict';
2
+
3
+ const path = require('path');
4
+ const defaultTo = require('./defaultTo');
5
+
6
+ function createConfig(config, argv, { port }) {
7
+ const firstWpOpt = Array.isArray(config) ? config[0] : config;
8
+ const options = firstWpOpt.devServer || {};
9
+
10
+ // This updates both config and firstWpOpt
11
+ firstWpOpt.mode = defaultTo(firstWpOpt.mode, 'development');
12
+
13
+ if (argv.bonjour) {
14
+ options.bonjour = true;
15
+ }
16
+
17
+ if (argv.host && (argv.host !== 'localhost' || !options.host)) {
18
+ options.host = argv.host;
19
+ }
20
+
21
+ if (argv.allowedHosts) {
22
+ options.allowedHosts = argv.allowedHosts.split(',');
23
+ }
24
+
25
+ if (argv.public) {
26
+ options.public = argv.public;
27
+ }
28
+
29
+ if (argv.socket) {
30
+ options.socket = argv.socket;
31
+ }
32
+
33
+ if (argv.progress) {
34
+ options.progress = argv.progress;
35
+ }
36
+
37
+ if (!options.publicPath) {
38
+ // eslint-disable-next-line
39
+ options.publicPath =
40
+ (firstWpOpt.output && firstWpOpt.output.publicPath) || '';
41
+
42
+ if (
43
+ !/^(https?:)?\/\//.test(options.publicPath) &&
44
+ options.publicPath[0] !== '/'
45
+ ) {
46
+ options.publicPath = `/${options.publicPath}`;
47
+ }
48
+ }
49
+
50
+ if (!options.filename && firstWpOpt.output && firstWpOpt.output.filename) {
51
+ options.filename = firstWpOpt.output && firstWpOpt.output.filename;
52
+ }
53
+
54
+ if (!options.watchOptions && firstWpOpt.watchOptions) {
55
+ options.watchOptions = firstWpOpt.watchOptions;
56
+ }
57
+
58
+ if (argv.stdin) {
59
+ process.stdin.on('end', () => {
60
+ // eslint-disable-next-line no-process-exit
61
+ process.exit(0);
62
+ });
63
+
64
+ process.stdin.resume();
65
+ }
66
+
67
+ // TODO https://github.com/webpack/webpack-dev-server/issues/616 (v4)
68
+ // We should prefer CLI arg under config, now we always prefer `hot` from `devServer`
69
+ if (!options.hot) {
70
+ options.hot = argv.hot;
71
+ }
72
+
73
+ // TODO https://github.com/webpack/webpack-dev-server/issues/616 (v4)
74
+ // We should prefer CLI arg under config, now we always prefer `hotOnly` from `devServer`
75
+ if (!options.hotOnly) {
76
+ options.hotOnly = argv.hotOnly;
77
+ }
78
+
79
+ // TODO https://github.com/webpack/webpack-dev-server/issues/616 (v4)
80
+ // We should prefer CLI arg under config, now we always prefer `clientLogLevel` from `devServer`
81
+ if (!options.clientLogLevel && argv.clientLogLevel) {
82
+ options.clientLogLevel = argv.clientLogLevel;
83
+ }
84
+
85
+ if (argv.contentBase) {
86
+ options.contentBase = argv.contentBase;
87
+
88
+ if (Array.isArray(options.contentBase)) {
89
+ options.contentBase = options.contentBase.map((p) => path.resolve(p));
90
+ } else if (/^[0-9]$/.test(options.contentBase)) {
91
+ options.contentBase = +options.contentBase;
92
+ } else if (!/^(https?:)?\/\//.test(options.contentBase)) {
93
+ options.contentBase = path.resolve(options.contentBase);
94
+ }
95
+ }
96
+ // It is possible to disable the contentBase by using
97
+ // `--no-content-base`, which results in arg["content-base"] = false
98
+ else if (argv.contentBase === false) {
99
+ options.contentBase = false;
100
+ }
101
+
102
+ if (argv.watchContentBase) {
103
+ options.watchContentBase = true;
104
+ }
105
+
106
+ if (!options.stats) {
107
+ options.stats = defaultTo(firstWpOpt.stats, {
108
+ cached: false,
109
+ cachedAssets: false,
110
+ });
111
+ }
112
+
113
+ if (
114
+ typeof options.stats === 'object' &&
115
+ typeof options.stats.colors === 'undefined' &&
116
+ argv.color
117
+ ) {
118
+ options.stats = Object.assign({}, options.stats, { colors: argv.color });
119
+ }
120
+
121
+ if (argv.lazy) {
122
+ options.lazy = true;
123
+ }
124
+
125
+ // TODO remove in `v4`
126
+ if (!argv.info) {
127
+ options.noInfo = true;
128
+ }
129
+
130
+ // TODO remove in `v4`
131
+ if (argv.quiet) {
132
+ options.quiet = true;
133
+ }
134
+
135
+ if (argv.https) {
136
+ options.https = true;
137
+ }
138
+
139
+ if (argv.http2) {
140
+ options.http2 = true;
141
+ }
142
+
143
+ if (argv.key) {
144
+ options.key = argv.key;
145
+ }
146
+
147
+ if (argv.cert) {
148
+ options.cert = argv.cert;
149
+ }
150
+
151
+ if (argv.cacert) {
152
+ options.ca = argv.cacert;
153
+ }
154
+
155
+ if (argv.pfx) {
156
+ options.pfx = argv.pfx;
157
+ }
158
+
159
+ if (argv.pfxPassphrase) {
160
+ options.pfxPassphrase = argv.pfxPassphrase;
161
+ }
162
+
163
+ if (argv.inline === false) {
164
+ options.inline = false;
165
+ }
166
+
167
+ if (argv.historyApiFallback) {
168
+ options.historyApiFallback = true;
169
+ }
170
+
171
+ if (argv.compress) {
172
+ options.compress = true;
173
+ }
174
+
175
+ if (argv.disableHostCheck) {
176
+ options.disableHostCheck = true;
177
+ }
178
+
179
+ if (argv.openPage) {
180
+ options.open = true;
181
+ options.openPage = argv.openPage;
182
+ }
183
+
184
+ if (typeof argv.open !== 'undefined') {
185
+ options.open = argv.open !== '' ? argv.open : true;
186
+ }
187
+
188
+ if (options.open && !options.openPage) {
189
+ options.openPage = '';
190
+ }
191
+
192
+ if (argv.useLocalIp) {
193
+ options.useLocalIp = true;
194
+ }
195
+
196
+ // Kind of weird, but ensures prior behavior isn't broken in cases
197
+ // that wouldn't throw errors. E.g. both argv.port and options.port
198
+ // were specified, but since argv.port is 8080, options.port will be
199
+ // tried first instead.
200
+ options.port =
201
+ argv.port === port
202
+ ? defaultTo(options.port, argv.port)
203
+ : defaultTo(argv.port, options.port);
204
+
205
+ return options;
206
+ }
207
+
208
+ module.exports = createConfig;
@@ -1,22 +1,16 @@
1
1
  'use strict';
2
2
 
3
- /* eslint-disable
4
- no-nested-ternary,
5
- multiline-ternary,
6
- space-before-function-paren
7
- */
8
3
  const url = require('url');
9
4
  const ip = require('internal-ip');
10
5
 
11
- function createDomain (options, server) {
6
+ function createDomain(options, server) {
12
7
  const protocol = options.https ? 'https' : 'http';
13
- const hostname = options.useLocalIp ? ip.v4.sync() || 'localhost' : options.host;
8
+ const hostname = options.useLocalIp
9
+ ? ip.v4.sync() || 'localhost'
10
+ : options.host || 'localhost';
14
11
 
15
- const port = options.socket
16
- ? 0
17
- : server
18
- ? server.address().port
19
- : 0;
12
+ // eslint-disable-next-line no-nested-ternary
13
+ const port = options.socket ? 0 : server ? server.address().port : 0;
20
14
  // use explicitly defined public url
21
15
  // (prefix with protocol if not explicitly given)
22
16
  if (options.public) {
@@ -28,7 +22,7 @@ function createDomain (options, server) {
28
22
  return url.format({
29
23
  protocol,
30
24
  hostname,
31
- port
25
+ port,
32
26
  });
33
27
  }
34
28
 
@@ -1,11 +1,8 @@
1
1
  'use strict';
2
2
 
3
- /* eslint-disable
4
- space-before-function-paren
5
- */
6
3
  const log = require('webpack-log');
7
4
 
8
- function createLogger (options) {
5
+ function createLogger(options) {
9
6
  let level = options.logLevel || 'info';
10
7
 
11
8
  if (options.noInfo === true) {
@@ -19,7 +16,7 @@ function createLogger (options) {
19
16
  return log({
20
17
  name: 'wds',
21
18
  level,
22
- timestamp: options.logTime
19
+ timestamp: options.logTime,
23
20
  });
24
21
  }
25
22
 
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ function defaultTo(value, def) {
4
+ return value == null ? def : value;
5
+ }
6
+
7
+ module.exports = defaultTo;
@@ -0,0 +1,35 @@
1
+ 'use strict';
2
+
3
+ const portfinder = require('portfinder');
4
+
5
+ function runPortFinder(defaultPort, cb) {
6
+ portfinder.basePort = defaultPort;
7
+ portfinder.getPort((err, port) => {
8
+ cb(err, port);
9
+ });
10
+ }
11
+
12
+ function findPort(server, defaultPort, defaultPortRetry, fn) {
13
+ let tryCount = 0;
14
+ const portFinderRunCb = (err, port) => {
15
+ tryCount += 1;
16
+ fn(err, port);
17
+ };
18
+
19
+ server.listeningApp.on('error', (err) => {
20
+ if (err && err.code !== 'EADDRINUSE') {
21
+ throw err;
22
+ }
23
+
24
+ if (tryCount >= defaultPortRetry) {
25
+ fn(err);
26
+ return;
27
+ }
28
+
29
+ runPortFinder(defaultPort, portFinderRunCb);
30
+ });
31
+
32
+ runPortFinder(defaultPort, portFinderRunCb);
33
+ }
34
+
35
+ module.exports = findPort;
@@ -0,0 +1,12 @@
1
+ 'use strict';
2
+
3
+ /* eslint-disable global-require */
4
+
5
+ function getVersions() {
6
+ return (
7
+ `webpack-dev-server ${require('../../package.json').version}\n` +
8
+ `webpack ${require('webpack/package.json').version}`
9
+ );
10
+ }
11
+
12
+ module.exports = getVersions;
@@ -0,0 +1,21 @@
1
+ 'use strict';
2
+
3
+ function runBonjour(options) {
4
+ // eslint-disable-next-line global-require
5
+ const bonjour = require('bonjour')();
6
+
7
+ bonjour.publish({
8
+ name: 'Webpack Dev Server',
9
+ port: options.port,
10
+ type: 'http',
11
+ subtypes: ['webpack'],
12
+ });
13
+
14
+ process.on('exit', () => {
15
+ bonjour.unpublishAll(() => {
16
+ bonjour.destroy();
17
+ });
18
+ });
19
+ }
20
+
21
+ module.exports = runBonjour;