webpack-dev-server 3.1.12 → 3.2.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/CHANGELOG.md +32 -0
- package/README.md +13 -7
- package/bin/options.js +33 -31
- package/bin/webpack-dev-server.js +26 -221
- package/client/index.bundle.js +1 -1
- package/client/index.js +58 -36
- package/client/live.bundle.js +3 -3
- package/client/overlay.js +18 -21
- package/client/socket.js +4 -5
- package/client/sockjs.bundle.js +1 -1
- package/client/webpack.config.js +14 -0
- package/lib/Server.js +748 -679
- package/lib/options.json +8 -24
- package/lib/utils/addEntries.js +20 -9
- package/lib/utils/colors.js +22 -0
- package/lib/utils/createCertificate.js +14 -17
- package/lib/utils/createConfig.js +204 -0
- package/lib/utils/createDomain.js +7 -13
- package/lib/utils/createLogger.js +2 -5
- package/lib/utils/defaultTo.js +7 -0
- package/lib/utils/getVersions.js +12 -0
- package/lib/utils/runBonjour.js +21 -0
- package/lib/utils/status.js +62 -0
- package/package.json +44 -25
- package/bin/utils.js +0 -114
package/lib/options.json
CHANGED
|
@@ -51,6 +51,9 @@
|
|
|
51
51
|
"socket": {
|
|
52
52
|
"type": "string"
|
|
53
53
|
},
|
|
54
|
+
"sockPath": {
|
|
55
|
+
"type": "string"
|
|
56
|
+
},
|
|
54
57
|
"watchOptions": {
|
|
55
58
|
"type": "object"
|
|
56
59
|
},
|
|
@@ -68,22 +71,10 @@
|
|
|
68
71
|
"type": "object"
|
|
69
72
|
},
|
|
70
73
|
"logLevel": {
|
|
71
|
-
"enum": [
|
|
72
|
-
"info",
|
|
73
|
-
"warn",
|
|
74
|
-
"error",
|
|
75
|
-
"debug",
|
|
76
|
-
"trace",
|
|
77
|
-
"silent"
|
|
78
|
-
]
|
|
74
|
+
"enum": ["info", "warn", "error", "debug", "trace", "silent"]
|
|
79
75
|
},
|
|
80
76
|
"clientLogLevel": {
|
|
81
|
-
"enum": [
|
|
82
|
-
"none",
|
|
83
|
-
"info",
|
|
84
|
-
"error",
|
|
85
|
-
"warning"
|
|
86
|
-
]
|
|
77
|
+
"enum": ["none", "info", "error", "warning"]
|
|
87
78
|
},
|
|
88
79
|
"overlay": {
|
|
89
80
|
"anyOf": [
|
|
@@ -174,9 +165,7 @@
|
|
|
174
165
|
"contentBase": {
|
|
175
166
|
"anyOf": [
|
|
176
167
|
{
|
|
177
|
-
"enum": [
|
|
178
|
-
false
|
|
179
|
-
]
|
|
168
|
+
"enum": [false]
|
|
180
169
|
},
|
|
181
170
|
{
|
|
182
171
|
"type": "number"
|
|
@@ -273,13 +262,7 @@
|
|
|
273
262
|
"type": "boolean"
|
|
274
263
|
},
|
|
275
264
|
{
|
|
276
|
-
"enum": [
|
|
277
|
-
"none",
|
|
278
|
-
"errors-only",
|
|
279
|
-
"minimal",
|
|
280
|
-
"normal",
|
|
281
|
-
"verbose"
|
|
282
|
-
]
|
|
265
|
+
"enum": ["none", "errors-only", "minimal", "normal", "verbose"]
|
|
283
266
|
}
|
|
284
267
|
]
|
|
285
268
|
},
|
|
@@ -321,6 +304,7 @@
|
|
|
321
304
|
"filename": "should be {String|RegExp|Function} (https://webpack.js.org/configuration/dev-server/#devserver-filename-)",
|
|
322
305
|
"port": "should be {String|Number} (https://webpack.js.org/configuration/dev-server/#devserver-port)",
|
|
323
306
|
"socket": "should be {String} (https://webpack.js.org/configuration/dev-server/#devserver-socket)",
|
|
307
|
+
"sockPath": "should be {String} (https://webpack.js.org/configuration/dev-server/#devserver-sockPath)",
|
|
324
308
|
"watchOptions": "should be {Object} (https://webpack.js.org/configuration/dev-server/#devserver-watchoptions)",
|
|
325
309
|
"writeToDisk": "should be {Boolean|Function} (https://github.com/webpack/webpack-dev-middleware#writetodisk)",
|
|
326
310
|
"headers": "should be {Object} (https://webpack.js.org/configuration/dev-server/#devserver-headers-)",
|
package/lib/utils/addEntries.js
CHANGED
|
@@ -1,14 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
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
|
|
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
|
|
@@ -16,11 +11,14 @@ function addEntries (config, options, server) {
|
|
|
16
11
|
const app = server || {
|
|
17
12
|
address() {
|
|
18
13
|
return { port: options.port };
|
|
19
|
-
}
|
|
14
|
+
},
|
|
20
15
|
};
|
|
21
16
|
|
|
22
17
|
const domain = createDomain(options, app);
|
|
23
|
-
const
|
|
18
|
+
const sockPath = options.sockPath ? `&sockPath=${options.sockPath}` : '';
|
|
19
|
+
const entries = [
|
|
20
|
+
`${require.resolve('../../client/')}?${domain}${sockPath}`,
|
|
21
|
+
];
|
|
24
22
|
|
|
25
23
|
if (options.hotOnly) {
|
|
26
24
|
entries.push(require.resolve('webpack/hot/only-dev-server'));
|
|
@@ -46,8 +44,21 @@ function addEntries (config, options, server) {
|
|
|
46
44
|
return entries.concat(entry);
|
|
47
45
|
};
|
|
48
46
|
|
|
47
|
+
// eslint-disable-next-line no-shadow
|
|
49
48
|
[].concat(config).forEach((config) => {
|
|
50
49
|
config.entry = prependEntry(config.entry || './src');
|
|
50
|
+
|
|
51
|
+
if (options.hot || options.hotOnly) {
|
|
52
|
+
config.plugins = config.plugins || [];
|
|
53
|
+
if (
|
|
54
|
+
!config.plugins.find(
|
|
55
|
+
(plugin) =>
|
|
56
|
+
plugin.constructor === webpack.HotModuleReplacementPlugin
|
|
57
|
+
)
|
|
58
|
+
) {
|
|
59
|
+
config.plugins.push(new webpack.HotModuleReplacementPlugin());
|
|
60
|
+
}
|
|
61
|
+
}
|
|
51
62
|
});
|
|
52
63
|
}
|
|
53
64
|
}
|
|
@@ -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
|
|
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,204 @@
|
|
|
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 = {
|
|
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.key) {
|
|
140
|
+
options.key = argv.key;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if (argv.cert) {
|
|
144
|
+
options.cert = argv.cert;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (argv.cacert) {
|
|
148
|
+
options.ca = argv.cacert;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (argv.pfx) {
|
|
152
|
+
options.pfx = argv.pfx;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if (argv.pfxPassphrase) {
|
|
156
|
+
options.pfxPassphrase = argv.pfxPassphrase;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
if (argv.inline === false) {
|
|
160
|
+
options.inline = false;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
if (argv.historyApiFallback) {
|
|
164
|
+
options.historyApiFallback = true;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if (argv.compress) {
|
|
168
|
+
options.compress = true;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
if (argv.disableHostCheck) {
|
|
172
|
+
options.disableHostCheck = true;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
if (argv.openPage) {
|
|
176
|
+
options.open = true;
|
|
177
|
+
options.openPage = argv.openPage;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
if (typeof argv.open !== 'undefined') {
|
|
181
|
+
options.open = argv.open !== '' ? argv.open : true;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
if (options.open && !options.openPage) {
|
|
185
|
+
options.openPage = '';
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
if (argv.useLocalIp) {
|
|
189
|
+
options.useLocalIp = true;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// Kind of weird, but ensures prior behavior isn't broken in cases
|
|
193
|
+
// that wouldn't throw errors. E.g. both argv.port and options.port
|
|
194
|
+
// were specified, but since argv.port is 8080, options.port will be
|
|
195
|
+
// tried first instead.
|
|
196
|
+
options.port =
|
|
197
|
+
argv.port === port
|
|
198
|
+
? defaultTo(options.port, argv.port)
|
|
199
|
+
: defaultTo(argv.port, options.port);
|
|
200
|
+
|
|
201
|
+
return options;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
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
|
|
6
|
+
function createDomain(options, server) {
|
|
12
7
|
const protocol = options.https ? 'https' : 'http';
|
|
13
|
-
const hostname = options.useLocalIp
|
|
8
|
+
const hostname = options.useLocalIp
|
|
9
|
+
? ip.v4.sync() || 'localhost'
|
|
10
|
+
: options.host;
|
|
14
11
|
|
|
15
|
-
|
|
16
|
-
|
|
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
|
|
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,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;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const open = require('opn');
|
|
4
|
+
const colors = require('./colors');
|
|
5
|
+
|
|
6
|
+
function status(uri, options, log, useColor) {
|
|
7
|
+
const contentBase = Array.isArray(options.contentBase)
|
|
8
|
+
? options.contentBase.join(', ')
|
|
9
|
+
: options.contentBase;
|
|
10
|
+
|
|
11
|
+
if (options.socket) {
|
|
12
|
+
log.info(`Listening to socket at ${colors.info(useColor, options.socket)}`);
|
|
13
|
+
} else {
|
|
14
|
+
log.info(`Project is running at ${colors.info(useColor, uri)}`);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
log.info(
|
|
18
|
+
`webpack output is served from ${colors.info(useColor, options.publicPath)}`
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
if (contentBase) {
|
|
22
|
+
log.info(
|
|
23
|
+
`Content not from webpack is served from ${colors.info(
|
|
24
|
+
useColor,
|
|
25
|
+
contentBase
|
|
26
|
+
)}`
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (options.historyApiFallback) {
|
|
31
|
+
log.info(
|
|
32
|
+
`404s will fallback to ${colors.info(
|
|
33
|
+
useColor,
|
|
34
|
+
options.historyApiFallback.index || '/index.html'
|
|
35
|
+
)}`
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (options.bonjour) {
|
|
40
|
+
log.info(
|
|
41
|
+
'Broadcasting "http" with subtype of "webpack" via ZeroConf DNS (Bonjour)'
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (options.open) {
|
|
46
|
+
let openOptions = {};
|
|
47
|
+
let openMessage = 'Unable to open browser';
|
|
48
|
+
|
|
49
|
+
if (typeof options.open === 'string') {
|
|
50
|
+
openOptions = { app: options.open };
|
|
51
|
+
openMessage += `: ${options.open}`;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
open(uri + (options.openPage || ''), openOptions).catch(() => {
|
|
55
|
+
log.warn(
|
|
56
|
+
`${openMessage}. If you are running in a headless environment, please do not use the --open flag`
|
|
57
|
+
);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
module.exports = status;
|