Skip to content

Commit 8b9040c

Browse files
evilebottnawialexander-akait
authored andcommitted
refactor: remove the hotOnly option (#2409)
BREAKING CHANGE: the `hotOnly` option was remove, please use `hot: "only"` instead
1 parent 6ecb4b1 commit 8b9040c

20 files changed

+132
-272
lines changed

bin/cli-flags.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,22 @@ module.exports = {
4949
describe: 'Print compilation progress in percentage',
5050
group: BASIC_GROUP,
5151
},
52+
{
53+
name: 'hot',
54+
type: Boolean,
55+
describe: 'Enables/Disables hot mode',
56+
group: ADVANCED_GROUP,
57+
},
5258
{
5359
name: 'hot-only',
5460
type: Boolean,
55-
describe: 'Do not refresh page if HMR fails',
61+
describe: 'Enables hot only mode',
5662
group: ADVANCED_GROUP,
5763
},
5864
{
5965
name: 'stdin',
6066
type: Boolean,
61-
describe: 'close when stdin ends',
67+
describe: 'Close when stdin ends',
6268
},
6369
{
6470
name: 'open',

bin/options.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,14 @@ const options = {
4545
describe: 'Print compilation progress in percentage',
4646
group: BASIC_GROUP,
4747
},
48+
hot: {
49+
type: 'boolean',
50+
describe: 'Enables/Disables hot mode',
51+
group: ADVANCED_GROUP,
52+
},
4853
'hot-only': {
4954
type: 'boolean',
50-
describe: 'Do not refresh page if HMR fails',
55+
describe: 'Enables hot only mode',
5156
group: ADVANCED_GROUP,
5257
},
5358
stdin: {

lib/Server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class Server {
9292

9393
this.sockets = [];
9494
this.contentBaseWatchers = [];
95-
this.hot = this.options.hot || this.options.hotOnly;
95+
this.hot = this.options.hot;
9696
this.watchOptions = options.watchOptions || {};
9797

9898
// Replace leading and trailing slashes to normalize path

lib/options.json

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,14 @@
114114
]
115115
},
116116
"hot": {
117-
"type": "boolean"
118-
},
119-
"hotOnly": {
120-
"type": "boolean"
117+
"anyOf": [
118+
{
119+
"type": "boolean"
120+
},
121+
{
122+
"enum": ["only"]
123+
}
124+
]
121125
},
122126
"http2": {
123127
"type": "boolean"
@@ -427,7 +431,6 @@
427431
"historyApiFallback": "should be {Boolean|Object} (https://webpack.js.org/configuration/dev-server/#devserverhistoryapifallback)",
428432
"host": "should be {String|Null} (https://webpack.js.org/configuration/dev-server/#devserverhost)",
429433
"hot": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserverhot)",
430-
"hotOnly": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserverhotonly)",
431434
"http2": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserverhttp2)",
432435
"https": "should be {Object|Boolean} (https://webpack.js.org/configuration/dev-server/#devserverhttps)",
433436
"index": "should be {String} (https://webpack.js.org/configuration/dev-server/#devserverindex)",

lib/utils/addEntries.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function addEntries(config, options, server) {
4343
/** @type {(string[] | string)} */
4444
let hotEntry;
4545

46-
if (options.hotOnly) {
46+
if (options.hot === 'only') {
4747
hotEntry = require.resolve('webpack/hot/only-dev-server');
4848
} else if (options.hot) {
4949
hotEntry = require.resolve('webpack/hot/dev-server');
@@ -134,7 +134,7 @@ function addEntries(config, options, server) {
134134

135135
config.entry = prependEntry(config.entry || './src', additionalEntries);
136136

137-
if (options.hot || options.hotOnly) {
137+
if (options.hot) {
138138
config.plugins = config.plugins || [];
139139
if (
140140
!config.plugins.find(

lib/utils/createConfig.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,7 @@ function createConfig(config, argv, { port }) {
8787
// TODO https://github.com/webpack/webpack-dev-server/issues/616 (v4)
8888
// We should prefer CLI arg under config, now we always prefer `hot` from `devServer`
8989
if (!options.hot) {
90-
options.hot = argv.hot;
91-
}
92-
93-
// TODO https://github.com/webpack/webpack-dev-server/issues/616 (v4)
94-
// We should prefer CLI arg under config, now we always prefer `hotOnly` from `devServer`
95-
if (!options.hotOnly) {
96-
options.hotOnly = argv.hotOnly;
90+
options.hot = argv.hotOnly ? 'only' : argv.hot;
9791
}
9892

9993
// TODO https://github.com/webpack/webpack-dev-server/issues/616 (v4)

lib/utils/updateCompiler.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ function updateCompiler(compiler, options) {
5757
});
5858

5959
// do not apply the plugin unless it didn't exist before.
60-
if (options.hot || options.hotOnly) {
60+
if (options.hot) {
6161
compilersWithoutHMR.forEach((compiler) => {
6262
// addDevServerEntrypoints above should have added the plugin
6363
// to the compiler options

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,11 @@ exports[`options should throw an error on the "host" option with "false" value 1
131131

132132
exports[`options should throw an error on the "hot" option with "" value 1`] = `
133133
"Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
134-
- options.hot should be a boolean."
135-
`;
136-
137-
exports[`options should throw an error on the "hotOnly" option with "" value 1`] = `
138-
"Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
139-
- options.hotOnly should be a boolean."
134+
- options.hot should be one of these:
135+
boolean | \\"only\\"
136+
Details:
137+
* options.hot should be a boolean.
138+
* options.hot should be \\"only\\"."
140139
`;
141140

142141
exports[`options should throw an error on the "http2" option with "" value 1`] = `

test/fixtures/schema/webpack.config.no-dev-stats.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ module.exports = {
1313
publicPath: '_publicPath',
1414
filename: '_filename',
1515
hot: '_hot',
16-
hotOnly: '_hotOnly',
1716
clientLogLevel: '_clientLogLevel',
1817
contentBase: '_contentBase',
1918
watchContentBase: '_watchContentBase',

test/helpers/test-server.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ function startFullSetup(config, options, done) {
2323
if (
2424
options.inline === undefined &&
2525
options.hot === undefined &&
26-
options.hotOnly === undefined &&
2726
options.liveReload === undefined
2827
) {
2928
options.inline = false;

0 commit comments

Comments
 (0)