Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/webpack-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ Options
-t, --target string Sets the build target
-w, --watch Watch for files changes
-h, --hot Enables Hot Module Replacement
--no-hot Disables Hot Module Replacement
-s, --sourcemap string Determine source maps to use
--prefetch string Prefetch this request
-j, --json Prints result as JSON
Expand Down
14 changes: 14 additions & 0 deletions packages/webpack-cli/__tests__/AdvancedGroup.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const AdvancedGroup = require('../lib/groups/AdvancedGroup');

describe('GroupHelper', function() {
it('should load the hot advanced config', () => {
const group = new AdvancedGroup([
{
hot: true,
},
]);

const result = group.run();
expect(result.options.plugins).toBeTruthy();
});
});
6 changes: 6 additions & 0 deletions packages/webpack-cli/lib/groups/AdvancedGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ class AdvancedGroup extends GroupHelper {
options.plugins = [hotModuleVal];
Comment thread
snitin315 marked this conversation as resolved.
}
}
if (args.noHot && args.hot) {
logger.warn('You provided both --hot and --no-hot. You should provide just one, "--hot" will be used')
}
if (args.noHot){
args.hot = false;
}
if (args.prefetch) {
const { PrefetchPlugin } = require('webpack');
const prefetchVal = new PrefetchPlugin(null, args.prefetch);
Expand Down
8 changes: 8 additions & 0 deletions packages/webpack-cli/lib/utils/cli-flags.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,14 @@ module.exports = {
description: 'Enables Hot Module Replacement',
link: 'https://webpack.js.org/concepts/hot-module-replacement/',
},
{
name: 'no-hot',
usage: 'webpack --no-hot',
type: Boolean,
group: ADVANCED_GROUP,
description: 'Disables Hot Module Replacement',
link: 'https://webpack.js.org/concepts/hot-module-replacement/',
},
{
name: 'sourcemap',
usage: '--sourcemap <sourcemap|eval|>',
Expand Down
28 changes: 28 additions & 0 deletions test/no-hot/no-hot.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'use strict';
const { run } = require('../utils/test-utils');
const { stat } = require('fs');
const { resolve } = require('path');
describe('no-hot flag', () => {
Comment thread
snitin315 marked this conversation as resolved.
it('should be successful when --no-hot is passed', done => {
const { stderr, stdout } = run(__dirname, ['--no-hot']);
expect(stderr).toBeFalsy();
expect(stdout).toBeTruthy();
stat(resolve(__dirname, './bin/main.js'), (err, stats) => {
expect(err).toBe(null);
expect(stats.isFile()).toBe(true);
done();
});
});

it('should use --hot when --hot and --no-hot are passed', done => {
const { stderr, stdout } = run(__dirname, ['--no-hot', '--hot']);
expect(stderr).toContain('"--hot" will be used');
expect(stdout).toBeTruthy();

stat(resolve(__dirname, './bin/main.js'), (err, stats) => {
expect(err).toBe(null);
expect(stats.isFile()).toBe(true);
done();
});
});
});
1 change: 1 addition & 0 deletions test/no-hot/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('HELLO WORLD') ;
1 change: 1 addition & 0 deletions test/no-hot/test-with-config/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('TEST WITH CONFIG');
16 changes: 16 additions & 0 deletions test/no-hot/test-with-config/no-hot-with-config.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict';
const { run } = require('../../utils/test-utils');
const { stat } = require('fs');
const { resolve } = require('path');
describe('no-hot flag', () => {
it('should be successful when --no-hot is passed', done => {
const { stderr, stdout } = run(__dirname, ['--no-hot']);
expect(stderr).toBeFalsy();
expect(stdout).toBeTruthy();
stat(resolve(__dirname, './bin/main.js'), (err, stats) => {
expect(err).toBe(null);
expect(stats.isFile()).toBe(true);
done();
});
});
});
7 changes: 7 additions & 0 deletions test/no-hot/test-with-config/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
mode: 'development',
entry: './index.js',
devServer: {
hot: true,
},
};
4 changes: 4 additions & 0 deletions test/no-hot/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
mode: 'development',
entry: './src/index.js',
};
6 changes: 6 additions & 0 deletions test/serve/serve-basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ describe('basic serve usage', () => {
expect(stderr).toHaveLength(0);
});

it('uses no-hot flag', async () => {
const { stdout, stderr } = await runServe(['--no-hot']);
expect(stdout).toContain('main.js');
expect(stderr).toHaveLength(0);
});

it('uses hot flag and progress flag', async () => {
const { stdout, stderr } = await runServe(['--hot', '--progress']);
expect(stdout).toContain('main.js');
Expand Down