Skip to content

Commit 8656e78

Browse files
authored
feat: allow string value for '--hot' (#2444)
1 parent 889646b commit 8656e78

File tree

4 files changed

+25
-3
lines changed

4 files changed

+25
-3
lines changed

OPTIONS.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Options:
1010
-m, --merge Merge two or more configurations using 'webpack-merge'.
1111
--env <value...> Environment passed to the configuration when it is a function.
1212
--node-env <value> Sets process.env.NODE_ENV to the specified value.
13-
-h, --hot Enables Hot Module Replacement
13+
-h, --hot [value] Enables Hot Module Replacement
1414
--no-hot Disables Hot Module Replacement.
1515
--analyze It invokes webpack-bundle-analyzer plugin to get bundle information.
1616
--progress [value] Print compilation progress during build.

packages/webpack-cli/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ npx webpack-cli --help verbose
9191
-d, --devtool <value> Determine source maps to use.
9292
--no-devtool Do not generate source maps.
9393
--entry <value...> The entry point(s) of your application e.g. ./src/main.js.
94-
-h, --hot Enables Hot Module Replacement
94+
-h, --hot [value] Enables Hot Module Replacement
9595
--no-hot Disables Hot Module Replacement
9696
--mode <value> Defines the mode to pass to webpack.
9797
--name <value> Name of the configuration. Used when loading multiple configurations.

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

+6-1
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ class WebpackCLI {
382382
{
383383
name: 'hot',
384384
alias: 'h',
385-
type: Boolean,
385+
type: [Boolean, String],
386386
negative: true,
387387
description: 'Enables Hot Module Replacement',
388388
negatedDescription: 'Disables Hot Module Replacement.',
@@ -1456,6 +1456,11 @@ class WebpackCLI {
14561456
process.exit(2);
14571457
}
14581458

1459+
if (typeof options.hot === 'string' && options.hot !== 'only') {
1460+
this.logger.error(`'${options.hot}' is an invalid value for the --hot option. Use 'only' instead.`);
1461+
process.exit(2);
1462+
}
1463+
14591464
const outputHints = (configOptions) => {
14601465
if (
14611466
configOptions.watch &&

test/hot/hot-flag.test.js

+17
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,23 @@ describe('--hot flag', () => {
1313
expect(readFileSync(resolve(__dirname, './dist/main.js')).toString()).toContain('webpackHotUpdate');
1414
});
1515

16+
it('should be successful when --hot=only is passed', () => {
17+
const { exitCode, stderr, stdout } = run(__dirname, ['--hot', 'only']);
18+
19+
expect(exitCode).toBe(0);
20+
expect(stderr).toBeFalsy();
21+
expect(stdout).toBeTruthy();
22+
expect(readFileSync(resolve(__dirname, './dist/main.js')).toString()).toContain('webpackHotUpdate');
23+
});
24+
25+
it('should throw an error for invalid value', () => {
26+
const { exitCode, stderr, stdout } = run(__dirname, ['--hot', 'unknown']);
27+
28+
expect(exitCode).toBe(2);
29+
expect(stderr).toContain(`[webpack-cli] 'unknown' is an invalid value for the --hot option. Use 'only' instead.`);
30+
expect(stdout).toBeFalsy();
31+
});
32+
1633
it('should be successful when --no-hot is passed', () => {
1734
const { exitCode, stderr, stdout } = run(__dirname, ['--no-hot']);
1835

0 commit comments

Comments
 (0)