Skip to content

Commit c0b073d

Browse files
authored
feat: add client.hotEntry and --client-hot-entry (#3294)
1 parent 5f657a2 commit c0b073d

14 files changed

+180
-29
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ Options:
108108
--no-http2 Do not use HTTP/2.
109109
--bonjour Broadcasts the server via ZeroConf networking on start.
110110
--no-bonjour Do not broadcast the server via ZeroConf networking on start.
111+
--client-hot-entry Tell devServer to inject a Hot Module Replacement entry.
112+
--no-client-hot-entry Do not tell devServer to inject a Hot Module Replacement entry.
111113
--client-progress Print compilation progress in percentage in the browser.
112114
--no-client-progress Do not print compilation progress in percentage in the browser.
113115
--client-overlay Show a full-screen overlay in the browser when there are compiler errors or warnings.

bin/cli-flags.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,24 @@ module.exports = {
244244
'Do not broadcast the server via ZeroConf networking on start.',
245245
negative: true,
246246
},
247+
{
248+
name: 'client-hot-entry',
249+
type: Boolean,
250+
configs: [
251+
{
252+
type: 'boolean',
253+
},
254+
],
255+
description: 'Tell devServer to inject a Hot Module Replacement entry.',
256+
negatedDescription:
257+
'Do not tell devServer to inject a Hot Module Replacement entry.',
258+
negative: true,
259+
processor(opts) {
260+
opts.client = opts.client || {};
261+
opts.client.hotEntry = opts.clientHotEntry;
262+
delete opts.clientHotEntry;
263+
},
264+
},
247265
{
248266
name: 'client-progress',
249267
type: Boolean,

lib/options.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@
270270
],
271271
"description": "Tells devServer to inject a client entry."
272272
},
273-
"needHotEntry": {
273+
"hotEntry": {
274274
"anyOf": [
275275
{
276276
"type": "boolean"

lib/utils/DevServerPlugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ class DevServerPlugin {
180180
if (
181181
hotEntry &&
182182
checkInject(
183-
options.client ? options.client.needHotEntry : null,
183+
options.client ? options.client.hotEntry : null,
184184
compilerOptions,
185185
true
186186
)

lib/utils/normalizeOptions.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,11 @@ function normalizeOptions(compiler, options) {
108108
options.client.overlay = true;
109109
}
110110

111+
// client.hotEntry
112+
if (typeof options.client.hotEntry === 'undefined') {
113+
options.client.hotEntry = options.hot;
114+
}
115+
111116
options.devMiddleware = options.devMiddleware || {};
112117

113118
if (typeof options.firewall === 'undefined') {

test/__snapshots__/validate-options.test.js.snap.webpack4

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@ exports[`options validate should throw an error on the "client" option with '{"h
1818
-> Tells clients connected to devServer to use the provided host."
1919
`;
2020

21+
exports[`options validate should throw an error on the "client" option with '{"hotEntry":[""]}' value 1`] = `
22+
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
23+
- configuration.client.hotEntry should be one of these:
24+
boolean | function
25+
-> Tells devServer to inject a Hot Module Replacement entry.
26+
Details:
27+
* configuration.client.hotEntry should be a boolean.
28+
* configuration.client.hotEntry should be an instance of function."
29+
`;
30+
2131
exports[`options validate should throw an error on the "client" option with '{"logging":"silent"}' value 1`] = `
2232
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
2333
- configuration.client.logging should be one of these:
@@ -40,16 +50,6 @@ exports[`options validate should throw an error on the "client" option with '{"n
4050
* configuration.client.needClientEntry should be an instance of function."
4151
`;
4252

43-
exports[`options validate should throw an error on the "client" option with '{"needHotEntry":[""]}' value 1`] = `
44-
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
45-
- configuration.client.needHotEntry should be one of these:
46-
boolean | function
47-
-> Tells devServer to inject a Hot Module Replacement entry.
48-
Details:
49-
* configuration.client.needHotEntry should be a boolean.
50-
* configuration.client.needHotEntry should be an instance of function."
51-
`;
52-
5353
exports[`options validate should throw an error on the "client" option with '{"overlay":""}' value 1`] = `
5454
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
5555
- configuration.client.overlay should be one of these:
@@ -110,14 +110,14 @@ exports[`options validate should throw an error on the "client" option with '{"t
110110
exports[`options validate should throw an error on the "client" option with '{"unknownOption":true}' value 1`] = `
111111
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
112112
- configuration.client has an unknown property 'unknownOption'. These properties are valid:
113-
object { transport?, host?, path?, port?, logging?, progress?, overlay?, needClientEntry?, needHotEntry? }
113+
object { transport?, host?, path?, port?, logging?, progress?, overlay?, needClientEntry?, hotEntry? }
114114
-> Specifies client properties. https://webpack.js.org/configuration/dev-server/#devserverclient"
115115
`;
116116

117117
exports[`options validate should throw an error on the "client" option with 'whoops!' value 1`] = `
118118
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
119119
- configuration.client should be an object:
120-
object { transport?, host?, path?, port?, logging?, progress?, overlay?, needClientEntry?, needHotEntry? }
120+
object { transport?, host?, path?, port?, logging?, progress?, overlay?, needClientEntry?, hotEntry? }
121121
-> Specifies client properties. https://webpack.js.org/configuration/dev-server/#devserverclient"
122122
`;
123123

test/__snapshots__/validate-options.test.js.snap.webpack5

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@ exports[`options validate should throw an error on the "client" option with '{"h
1818
-> Tells clients connected to devServer to use the provided host."
1919
`;
2020

21+
exports[`options validate should throw an error on the "client" option with '{"hotEntry":[""]}' value 1`] = `
22+
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
23+
- configuration.client.hotEntry should be one of these:
24+
boolean | function
25+
-> Tells devServer to inject a Hot Module Replacement entry.
26+
Details:
27+
* configuration.client.hotEntry should be a boolean.
28+
* configuration.client.hotEntry should be an instance of function."
29+
`;
30+
2131
exports[`options validate should throw an error on the "client" option with '{"logging":"silent"}' value 1`] = `
2232
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
2333
- configuration.client.logging should be one of these:
@@ -40,16 +50,6 @@ exports[`options validate should throw an error on the "client" option with '{"n
4050
* configuration.client.needClientEntry should be an instance of function."
4151
`;
4252

43-
exports[`options validate should throw an error on the "client" option with '{"needHotEntry":[""]}' value 1`] = `
44-
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
45-
- configuration.client.needHotEntry should be one of these:
46-
boolean | function
47-
-> Tells devServer to inject a Hot Module Replacement entry.
48-
Details:
49-
* configuration.client.needHotEntry should be a boolean.
50-
* configuration.client.needHotEntry should be an instance of function."
51-
`;
52-
5353
exports[`options validate should throw an error on the "client" option with '{"overlay":""}' value 1`] = `
5454
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
5555
- configuration.client.overlay should be one of these:
@@ -110,14 +110,14 @@ exports[`options validate should throw an error on the "client" option with '{"t
110110
exports[`options validate should throw an error on the "client" option with '{"unknownOption":true}' value 1`] = `
111111
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
112112
- configuration.client has an unknown property 'unknownOption'. These properties are valid:
113-
object { transport?, host?, path?, port?, logging?, progress?, overlay?, needClientEntry?, needHotEntry? }
113+
object { transport?, host?, path?, port?, logging?, progress?, overlay?, needClientEntry?, hotEntry? }
114114
-> Specifies client properties. https://webpack.js.org/configuration/dev-server/#devserverclient"
115115
`;
116116

117117
exports[`options validate should throw an error on the "client" option with 'whoops!' value 1`] = `
118118
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
119119
- configuration.client should be an object:
120-
object { transport?, host?, path?, port?, logging?, progress?, overlay?, needClientEntry?, needHotEntry? }
120+
object { transport?, host?, path?, port?, logging?, progress?, overlay?, needClientEntry?, hotEntry? }
121121
-> Specifies client properties. https://webpack.js.org/configuration/dev-server/#devserverclient"
122122
`;
123123

test/cli/__snapshots__/cli.test.js.snap.webpack4

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,10 @@ Options:
237237
networking on start.
238238
--no-bonjour Do not broadcast the server via ZeroConf
239239
networking on start.
240+
--client-hot-entry Tell devServer to inject a Hot Module
241+
Replacement entry.
242+
--no-client-hot-entry Do not tell devServer to inject a Hot Module
243+
Replacement entry.
240244
--client-progress Print compilation progress in percentage in
241245
the browser.
242246
--no-client-progress Do not print compilation progress in

test/cli/__snapshots__/cli.test.js.snap.webpack5

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,10 @@ Options:
238238
networking on start.
239239
--no-bonjour Do not broadcast the server via ZeroConf
240240
networking on start.
241+
--client-hot-entry Tell devServer to inject a Hot Module
242+
Replacement entry.
243+
--no-client-hot-entry Do not tell devServer to inject a Hot Module
244+
Replacement entry.
241245
--client-progress Print compilation progress in percentage in
242246
the browser.
243247
--no-client-progress Do not print compilation progress in

test/cli/cli.test.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,50 @@ describe('CLI', () => {
105105
.catch(done);
106106
});
107107

108+
it('--client-hot-entry', (done) => {
109+
testBin('--client-hot-entry --stats=detailed')
110+
.then((output) => {
111+
expect(output.exitCode).toEqual(0);
112+
expect(output.stdout).toContain('webpack/hot/dev-server.js');
113+
114+
done();
115+
})
116+
.catch(done);
117+
});
118+
119+
it('--no-client-hot-entry', (done) => {
120+
testBin('--no-client-hot-entry --stats=detailed')
121+
.then((output) => {
122+
expect(output.exitCode).toEqual(0);
123+
expect(output.stdout).not.toContain('webpack/hot/dev-server.js');
124+
125+
done();
126+
})
127+
.catch(done);
128+
});
129+
130+
it('should not inject HMR entry "--client-hot-entry" and "--no-hot"', (done) => {
131+
testBin('--client-hot-entry --no-hot --stats=detailed')
132+
.then((output) => {
133+
expect(output.exitCode).toEqual(0);
134+
expect(output.stdout).not.toContain('webpack/hot/dev-server.js');
135+
136+
done();
137+
})
138+
.catch(done);
139+
});
140+
141+
it('should not inject HMR entry with "--no-client-hot-entry" and "--hot"', (done) => {
142+
testBin('--no-client-hot-entry --hot --stats=detailed')
143+
.then((output) => {
144+
expect(output.exitCode).toEqual(0);
145+
expect(output.stdout).not.toContain('webpack/hot/dev-server.js');
146+
147+
done();
148+
})
149+
.catch(done);
150+
});
151+
108152
it('--http2', (done) => {
109153
testBin('--http2')
110154
.then((output) => {

test/server/clientOptions-option.test.js renamed to test/server/client-option.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ describe('client option', () => {
9696
config,
9797
{
9898
client: {
99-
needHotEntry: false,
99+
hotEntry: false,
100100
},
101101
port,
102102
},

0 commit comments

Comments
 (0)