Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow string value for '--hot' #2444

Merged
merged 2 commits into from Mar 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion OPTIONS.md
Expand Up @@ -10,7 +10,7 @@ Options:
-m, --merge Merge two or more configurations using 'webpack-merge'.
--env <value...> Environment passed to the configuration when it is a function.
--node-env <value> Sets process.env.NODE_ENV to the specified value.
-h, --hot Enables Hot Module Replacement
-h, --hot [value] Enables Hot Module Replacement
--no-hot Disables Hot Module Replacement.
--analyze It invokes webpack-bundle-analyzer plugin to get bundle information.
--progress [value] Print compilation progress during build.
Expand Down
2 changes: 1 addition & 1 deletion packages/webpack-cli/README.md
Expand Up @@ -91,7 +91,7 @@ npx webpack-cli --help verbose
-d, --devtool <value> Determine source maps to use.
--no-devtool Do not generate source maps.
--entry <value...> The entry point(s) of your application e.g. ./src/main.js.
-h, --hot Enables Hot Module Replacement
-h, --hot [value] Enables Hot Module Replacement
--no-hot Disables Hot Module Replacement
--mode <value> Defines the mode to pass to webpack.
--name <value> Name of the configuration. Used when loading multiple configurations.
Expand Down
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