Skip to content
This repository was archived by the owner on Jul 13, 2021. It is now read-only.

Commit 1e6c6b2

Browse files
authored
fix: multiple entries, add autoConfigure option (#58)
* fix: multicompiler entries, add autoConfigure option * docs: add autoConfigure docs
1 parent 411ecf9 commit 1e6c6b2

9 files changed

Lines changed: 255 additions & 117 deletions

File tree

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,14 @@ Returns an `Object` containing:
102102

103103
Type: `Object`
104104

105+
##### autoConfigure
106+
107+
Type: `Boolean`
108+
Default: `true`
109+
110+
If true, automatically configures the `entry` for the webpack compiler, and adds
111+
the `HotModuleReplacementPlugin` to the compiler.
112+
105113
##### host
106114

107115
Type: `String|Object`
@@ -258,4 +266,4 @@ We welcome your contributions! Please have a read of [CONTRIBUTING.md](CONTRIBUT
258266
[dev-server]: https://github.com/webpack/webpack-dev-server
259267
[hmr-docs]: https://webpack.js.org/concepts/hot-module-replacement/
260268
[stats]: https://webpack.js.org/configuration/stats/#stats
261-
[levels]: https://github.com/webpack-contrib/webpack-log#level
269+
[levels]: https://github.com/webpack-contrib/webpack-log#level

index.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const HotClientError = require('./lib/HotClientError');
77
const { modifyCompiler, payload, sendData, validateCompiler } = require('./lib/util');
88

99
const defaults = {
10+
autoConfigure: true,
1011
host: 'localhost',
1112
hot: true,
1213
https: false,
@@ -60,7 +61,9 @@ module.exports = (compiler, opts) => {
6061
log.warn('`options.host.client` does not match `options.host.server`. This can cause unpredictable behavior in the browser.');
6162
}
6263

63-
validateCompiler(compiler);
64+
if (options.autoConfigure) {
65+
validateCompiler(compiler);
66+
}
6467

6568
const { host, port, server } = options;
6669
const wssOptions = options.server ? { server } : { host: host.server, port };
@@ -93,7 +96,9 @@ module.exports = (compiler, opts) => {
9396
options.webSocket = { host: host.client, port };
9497
}
9598

96-
modifyCompiler(compiler, options);
99+
if (options.autoConfigure) {
100+
modifyCompiler(compiler, options);
101+
}
97102

98103
const compile = (comp) => {
99104
const compilerName = comp.name || '<unnamed compiler>';
@@ -176,7 +181,9 @@ module.exports = (compiler, opts) => {
176181
}
177182
});
178183

179-
if (stats) {
184+
// only send stats to newly connected clients if no previous clients have
185+
// connected
186+
if (stats && !wss.clients.length) {
180187
const jsonStats = stats.toJson(options.stats);
181188

182189
/* istanbul ignore if */

lib/util.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,8 @@ function addEntry(entry, compilerName) {
1111
let newEntry = {};
1212

1313
if (!Array.isArray(entry) && typeof entry === 'object') {
14-
for (const key of Object.keys(entry)) {
15-
const value = entry[key];
16-
if (Array.isArray(value)) {
17-
newEntry[key] = clientEntry.concat(value);
18-
}
19-
}
14+
const [first] = Object.keys(entry);
15+
newEntry[first] = clientEntry.concat(entry[first]);
2016
} else {
2117
newEntry = clientEntry.concat(entry);
2218
}

package-lock.json

Lines changed: 103 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,13 @@
4646
"@babel/preset-env": "^7.0.0-beta.37",
4747
"@babel/register": "^7.0.0-beta.37",
4848
"ansi-regex": "^3.0.0",
49-
"assert": "^1.4.1",
5049
"babel-loader": "^8.0.0-beta.0",
5150
"codecov": "^3.0.0",
5251
"eslint": "^4.6.1",
5352
"eslint-config-webpack": "^1.2.5",
5453
"eslint-plugin-import": "^2.8.0",
54+
"expect": "^22.4.3",
55+
"loud-rejection": "^1.6.0",
5556
"memory-fs": "^0.4.1",
5657
"mocha": "^5.0.0",
5758
"nyc": "^11.4.1",

test/test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,10 @@ if (parseInt(process.version.substring(1), 10) < 8) {
1616
});
1717
}
1818

19+
require('loud-rejection/register');
20+
21+
global.expect = require('expect');
22+
1923
require('./tests/init');
24+
require('./tests/options');
2025
require('./tests/sockets');

0 commit comments

Comments
 (0)