Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions bin/cli-flags.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,22 @@ module.exports = {
describe: 'Print compilation progress in percentage',
group: BASIC_GROUP,
},
{
name: 'hot',
type: Boolean,
describe: 'Enables/Disables hot mode',
group: ADVANCED_GROUP,
},
{
name: 'hot-only',
type: Boolean,
describe: 'Do not refresh page if HMR fails',
describe: 'Enables hot only mode',
group: ADVANCED_GROUP,
},
{
name: 'stdin',
type: Boolean,
describe: 'close when stdin ends',
describe: 'Close when stdin ends',
},
{
name: 'open',
Expand Down
7 changes: 6 additions & 1 deletion bin/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,14 @@ const options = {
describe: 'Print compilation progress in percentage',
group: BASIC_GROUP,
},
hot: {
type: 'boolean',
describe: 'Enables/Disables hot mode',
group: ADVANCED_GROUP,
},
'hot-only': {
type: 'boolean',
describe: 'Do not refresh page if HMR fails',
describe: 'Enables hot only mode',
group: ADVANCED_GROUP,
},
stdin: {
Expand Down
2 changes: 1 addition & 1 deletion lib/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class Server {

this.sockets = [];
this.contentBaseWatchers = [];
this.hot = this.options.hot || this.options.hotOnly;
this.hot = this.options.hot;
this.watchOptions = options.watchOptions || {};

// Replace leading and trailing slashes to normalize path
Expand Down
13 changes: 8 additions & 5 deletions lib/options.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,14 @@
]
},
"hot": {
"type": "boolean"
},
"hotOnly": {
"type": "boolean"
"anyOf": [
{
"type": "boolean"
},
{
"enum": ["only"]
}
]
},
"http2": {
"type": "boolean"
Expand Down Expand Up @@ -427,7 +431,6 @@
"historyApiFallback": "should be {Boolean|Object} (https://webpack.js.org/configuration/dev-server/#devserverhistoryapifallback)",
"host": "should be {String|Null} (https://webpack.js.org/configuration/dev-server/#devserverhost)",
"hot": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserverhot)",
"hotOnly": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserverhotonly)",
"http2": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserverhttp2)",
"https": "should be {Object|Boolean} (https://webpack.js.org/configuration/dev-server/#devserverhttps)",
"index": "should be {String} (https://webpack.js.org/configuration/dev-server/#devserverindex)",
Expand Down
4 changes: 2 additions & 2 deletions lib/utils/addEntries.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function addEntries(config, options, server) {
/** @type {(string[] | string)} */
let hotEntry;

if (options.hotOnly) {
if (options.hot === 'only') {
hotEntry = require.resolve('webpack/hot/only-dev-server');
} else if (options.hot) {
hotEntry = require.resolve('webpack/hot/dev-server');
Expand Down Expand Up @@ -134,7 +134,7 @@ function addEntries(config, options, server) {

config.entry = prependEntry(config.entry || './src', additionalEntries);

if (options.hot || options.hotOnly) {
if (options.hot) {
config.plugins = config.plugins || [];
if (
!config.plugins.find(
Expand Down
8 changes: 1 addition & 7 deletions lib/utils/createConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,7 @@ function createConfig(config, argv, { port }) {
// TODO https://github.com/webpack/webpack-dev-server/issues/616 (v4)
// We should prefer CLI arg under config, now we always prefer `hot` from `devServer`
if (!options.hot) {
options.hot = argv.hot;
}

// TODO https://github.com/webpack/webpack-dev-server/issues/616 (v4)
// We should prefer CLI arg under config, now we always prefer `hotOnly` from `devServer`
if (!options.hotOnly) {
options.hotOnly = argv.hotOnly;
options.hot = argv.hotOnly ? 'only' : argv.hot;
}

// TODO https://github.com/webpack/webpack-dev-server/issues/616 (v4)
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/updateCompiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function updateCompiler(compiler, options) {
});

// do not apply the plugin unless it didn't exist before.
if (options.hot || options.hotOnly) {
if (options.hot) {
compilersWithoutHMR.forEach((compiler) => {
// addDevServerEntrypoints above should have added the plugin
// to the compiler options
Expand Down
11 changes: 5 additions & 6 deletions test/__snapshots__/validate-options.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,11 @@ exports[`options should throw an error on the "host" option with "false" value 1

exports[`options should throw an error on the "hot" option with "" value 1`] = `
"Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
- options.hot should be a boolean."
`;

exports[`options should throw an error on the "hotOnly" option with "" value 1`] = `
"Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
- options.hotOnly should be a boolean."
- options.hot should be one of these:
boolean | \\"only\\"
Details:
* options.hot should be a boolean.
* options.hot should be \\"only\\"."
`;

exports[`options should throw an error on the "http2" option with "" value 1`] = `
Expand Down
1 change: 0 additions & 1 deletion test/fixtures/schema/webpack.config.no-dev-stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ module.exports = {
publicPath: '_publicPath',
filename: '_filename',
hot: '_hot',
hotOnly: '_hotOnly',
clientLogLevel: '_clientLogLevel',
contentBase: '_contentBase',
watchContentBase: '_watchContentBase',
Expand Down
1 change: 0 additions & 1 deletion test/helpers/test-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ function startFullSetup(config, options, done) {
if (
options.inline === undefined &&
options.hot === undefined &&
options.hotOnly === undefined &&
options.liveReload === undefined
) {
options.inline = false;
Expand Down
1 change: 0 additions & 1 deletion test/ports-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ const portsList = {
'historyApiFallback-option': 1,
'host-option': 1,
'hot-option': 1,
'hotOnly-option': 1,
'http2-option': 1,
'https-option': 1,
'inline-option': 1,
Expand Down
4 changes: 2 additions & 2 deletions test/server/Server.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ describe('Server', () => {
compiler.run(() => {});
});

it('add hotOnly option', (done) => {
it('add hot with the "only" value option', (done) => {
const compiler = webpack(config);
const server = new Server(
compiler,
Object.assign({}, baseDevConfig, {
hotOnly: true,
hot: 'only',
})
);

Expand Down
2 changes: 1 addition & 1 deletion test/server/__snapshots__/Server.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Array [
]
`;

exports[`Server addEntries add hotOnly option 1`] = `
exports[`Server addEntries add hot with the "only" value option 1`] = `
Array [
Array [
"client",
Expand Down
59 changes: 59 additions & 0 deletions test/server/hot-option.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,63 @@ describe('hot option', () => {

afterAll(testServer.close);
});

describe('simple hot only config entries', () => {
beforeAll((done) => {
const options = {
port,
inline: true,
hot: 'only',
watchOptions: {
poll: true,
},
};
server = testServer.startAwaitingCompilation(config, options, done);
req = request(server.app);
});

afterAll(testServer.close);

it('should include hot only script in the bundle', async () => {
await req
.get('/main.js')
.expect(200, /webpack\/hot\/only-dev-server\.js/);
});
});

describe('simple hot only config HMR plugin', () => {
it('should register the HMR plugin before compilation is complete', (done) => {
let pluginFound = false;

const options = {
port,
inline: true,
hot: 'only',
watchOptions: {
poll: true,
},
};
const fullSetup = testServer.startAwaitingCompilationFullSetup(
config,
options,
() => {
expect(pluginFound).toBeTruthy();
done();
}
);

const compiler = fullSetup.compiler;

compiler.hooks.compilation.intercept({
register: (tapInfo) => {
if (tapInfo.name === 'HotModuleReplacementPlugin') {
pluginFound = true;
}
return tapInfo;
},
});
});

afterAll(testServer.close);
});
});
68 changes: 0 additions & 68 deletions test/server/hotOnly-option.test.js

This file was deleted.

2 changes: 1 addition & 1 deletion test/server/open-option.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('open option', () => {
server.close(() => {
expect(open.mock.calls[0]).toMatchInlineSnapshot(`
Array [
"http://localhost:8120/",
"http://localhost:8119/",
Object {
"wait": false,
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`WebsocketServer server should recieve connection, send message, and close client 1`] = `"localhost:8131"`;
exports[`WebsocketServer server should recieve connection, send message, and close client 1`] = `"localhost:8130"`;

exports[`WebsocketServer server should recieve connection, send message, and close client 2`] = `
Array [
Expand Down
Loading