Skip to content

Commit 43738e6

Browse files
authored
refactor: remove --hot (#2833)
BRAKING CHANGE: the `--hot` option was removed for `webpack build` and `webpack watch` commands in favor directly usage `HotModuleReplacement` plugin
1 parent 3e2bb73 commit 43738e6

14 files changed

Lines changed: 49 additions & 203 deletions

packages/serve/src/index.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,9 @@ class ServeCommand {
9090

9191
for (const optionName in options) {
9292
const kebabedOption = cli.utils.toKebabCase(optionName);
93-
// `webpack-dev-server` has own logic for the `--hot` option
94-
const isBuiltInOption =
95-
kebabedOption !== "hot" &&
96-
builtInOptions.find(
97-
(builtInOption) => builtInOption.name === kebabedOption,
98-
);
93+
const isBuiltInOption = builtInOptions.find(
94+
(builtInOption) => builtInOption.name === kebabedOption,
95+
);
9996

10097
if (isBuiltInOption) {
10198
webpackCLIOptions[optionName] = options[optionName];

packages/webpack-cli/lib/plugins/CLIPlugin.js

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,6 @@ class CLIPlugin {
33
this.options = options;
44
}
55

6-
setupHotPlugin(compiler) {
7-
const { HotModuleReplacementPlugin } = compiler.webpack || require("webpack");
8-
const hotModuleReplacementPlugin = Boolean(
9-
compiler.options.plugins.find((plugin) => plugin instanceof HotModuleReplacementPlugin),
10-
);
11-
12-
if (!hotModuleReplacementPlugin) {
13-
new HotModuleReplacementPlugin().apply(compiler);
14-
}
15-
}
16-
176
setupPrefetchPlugin(compiler) {
187
const { PrefetchPlugin } = compiler.webpack || require("webpack");
198

@@ -119,10 +108,6 @@ class CLIPlugin {
119108
this.setupProgressPlugin(compiler);
120109
}
121110

122-
if (this.options.hot) {
123-
this.setupHotPlugin(compiler);
124-
}
125-
126111
if (this.options.prefetch) {
127112
this.setupPrefetchPlugin(compiler);
128113
}

packages/webpack-cli/lib/webpack-cli.js

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -504,21 +504,6 @@ class WebpackCLI {
504504
},
505505

506506
// Adding more plugins
507-
{
508-
name: "hot",
509-
alias: "h",
510-
configs: [
511-
{
512-
type: "string",
513-
},
514-
{
515-
type: "boolean",
516-
},
517-
],
518-
negative: true,
519-
description: "Enables Hot Module Replacement",
520-
negatedDescription: "Disables Hot Module Replacement.",
521-
},
522507
{
523508
name: "analyze",
524509
configs: [
@@ -1758,13 +1743,6 @@ class WebpackCLI {
17581743
process.exit(2);
17591744
}
17601745

1761-
if (typeof options.hot === "string" && options.hot !== "only") {
1762-
this.logger.error(
1763-
`'${options.hot}' is an invalid value for the --hot option. Use 'only' instead.`,
1764-
);
1765-
process.exit(2);
1766-
}
1767-
17681746
const outputHints = (configOptions) => {
17691747
if (
17701748
configOptions.watch &&
@@ -2024,7 +2002,6 @@ class WebpackCLI {
20242002
new CLIPlugin({
20252003
configPath: config.path.get(configOptions),
20262004
helpfulOutput: !cliOptions.json,
2027-
hot: cliOptions.hot,
20282005
progress: cliOptions.progress,
20292006
prefetch: cliOptions.prefetch,
20302007
analyze: cliOptions.analyze,

test/build/hot/__snapshots__/hot-flag.test.js.snap.webpack4

Lines changed: 0 additions & 11 deletions
This file was deleted.

test/build/hot/__snapshots__/hot-flag.test.js.snap.webpack5

Lines changed: 0 additions & 11 deletions
This file was deleted.

test/build/hot/hot-flag.test.js

Lines changed: 0 additions & 47 deletions
This file was deleted.

test/build/hot/src/index.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/build/hot/webpack.config.js

Lines changed: 0 additions & 4 deletions
This file was deleted.

test/serve/basic/__snapshots__/serve-basic.test.js.snap.devServer3.webpack4

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,30 +47,20 @@ exports[`basic serve usage should work and log warning on the \`watch option in
4747

4848
exports[`basic serve usage should work in multi compiler mode: stderr 1`] = `""`;
4949

50-
exports[`basic serve usage should work with "--hot" and "--port" options: stderr 1`] = `""`;
51-
5250
exports[`basic serve usage should work with entries syntax: stderr 1`] = `""`;
5351

5452
exports[`basic serve usage should work with the "--client-log-level" option: stderr 1`] = `""`;
5553

56-
exports[`basic serve usage should work with the "--config" and "--env" options and expose dev server options: stderr 1`] = `""`;
57-
5854
exports[`basic serve usage should work with the "--config" and "--env" options: stderr 1`] = `""`;
5955

6056
exports[`basic serve usage should work with the "--config" option: stderr 1`] = `""`;
6157

62-
exports[`basic serve usage should work with the "--hot" option using the "only" value: stderr 1`] = `""`;
63-
64-
exports[`basic serve usage should work with the "--hot" option: stderr 1`] = `""`;
65-
6658
exports[`basic serve usage should work with the "--mode" option #2: stderr 1`] = `""`;
6759

6860
exports[`basic serve usage should work with the "--mode" option #3: stderr 1`] = `""`;
6961

7062
exports[`basic serve usage should work with the "--mode" option: stderr 1`] = `""`;
7163

72-
exports[`basic serve usage should work with the "--no-hot" option: stderr 1`] = `""`;
73-
7464
exports[`basic serve usage should work with the "--open" option: stderr 1`] = `""`;
7565

7666
exports[`basic serve usage should work with the "--output-public-path" option: stderr 1`] = `

test/serve/basic/__snapshots__/serve-basic.test.js.snap.devServer3.webpack5

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,30 +47,20 @@ exports[`basic serve usage should work and log warning on the \`watch option in
4747

4848
exports[`basic serve usage should work in multi compiler mode: stderr 1`] = `""`;
4949

50-
exports[`basic serve usage should work with "--hot" and "--port" options: stderr 1`] = `""`;
51-
5250
exports[`basic serve usage should work with entries syntax: stderr 1`] = `""`;
5351

5452
exports[`basic serve usage should work with the "--client-log-level" option: stderr 1`] = `""`;
5553

56-
exports[`basic serve usage should work with the "--config" and "--env" options and expose dev server options: stderr 1`] = `""`;
57-
5854
exports[`basic serve usage should work with the "--config" and "--env" options: stderr 1`] = `""`;
5955

6056
exports[`basic serve usage should work with the "--config" option: stderr 1`] = `""`;
6157

62-
exports[`basic serve usage should work with the "--hot" option using the "only" value: stderr 1`] = `""`;
63-
64-
exports[`basic serve usage should work with the "--hot" option: stderr 1`] = `""`;
65-
6658
exports[`basic serve usage should work with the "--mode" option #2: stderr 1`] = `""`;
6759

6860
exports[`basic serve usage should work with the "--mode" option #3: stderr 1`] = `""`;
6961

7062
exports[`basic serve usage should work with the "--mode" option: stderr 1`] = `""`;
7163

72-
exports[`basic serve usage should work with the "--no-hot" option: stderr 1`] = `""`;
73-
7464
exports[`basic serve usage should work with the "--open" option: stderr 1`] = `""`;
7565

7666
exports[`basic serve usage should work with the "--output-public-path" option: stderr 1`] = `""`;

0 commit comments

Comments
 (0)