Skip to content

Commit

Permalink
feat: allow string value for '--hot'
Browse files Browse the repository at this point in the history
  • Loading branch information
snitin315 committed Feb 19, 2021
1 parent 74ed07b commit 89294ac
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/webpack-cli/lib/webpack-cli.js
Expand Up @@ -307,7 +307,7 @@ class WebpackCLI {
{
name: 'hot',
alias: 'h',
type: Boolean,
type: [Boolean, String],
negative: true,
description: 'Enables Hot Module Replacement',
negatedDescription: 'Disables Hot Module Replacement.',
Expand Down Expand Up @@ -1383,6 +1383,11 @@ class WebpackCLI {
process.exit(2);
}

if (typeof options.hot === 'string' && options.hot !== 'only') {
this.logger.error(`'${options.hot}' is an invalid value for the --hot option. Use 'only' instead.`);
process.exit(2);
}

const outputHints = (configOptions) => {
if (
configOptions.watch &&
Expand Down
17 changes: 17 additions & 0 deletions test/hot/hot-flag.test.js
Expand Up @@ -13,6 +13,23 @@ describe('--hot flag', () => {
expect(readFileSync(resolve(__dirname, './dist/main.js')).toString()).toContain('webpackHotUpdate');
});

it('should be successful when --hot=only is passed', () => {
const { exitCode, stderr, stdout } = run(__dirname, ['--hot', 'only']);

expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
expect(stdout).toBeTruthy();
expect(readFileSync(resolve(__dirname, './dist/main.js')).toString()).toContain('webpackHotUpdate');
});

it('should throw an error for invalid value', () => {
const { exitCode, stderr, stdout } = run(__dirname, ['--hot', 'unknown']);

expect(exitCode).toBe(2);
expect(stderr).toContain(`[webpack-cli] 'unknown' is an invalid value for the --hot option. Use 'only' instead.`);
expect(stdout).toBeFalsy();
});

it('should be successful when --no-hot is passed', () => {
const { exitCode, stderr, stdout } = run(__dirname, ['--no-hot']);

Expand Down

0 comments on commit 89294ac

Please sign in to comment.