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

fix(hot): enable hot option as default #2546

Merged
merged 5 commits into from
Apr 28, 2020
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
9 changes: 7 additions & 2 deletions lib/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ class Server {

normalizeOptions(this.compiler, this.options);

// don't move this position because addEntries called by updateCompiler checks this.options.hot|hotOnly
this.options.hot =
typeof this.options.hot === 'boolean' || this.options.hot === 'only'
? this.options.hot
: true;

updateCompiler(this.compiler, this.options);

this.heartbeatInterval = 30000;
Expand All @@ -86,7 +92,6 @@ class Server {
this.contentBaseWatchers = [];

// TODO this.<property> is deprecated (remove them in next major release.) in favor this.options.<property>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove TODO

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? this task hasn't been completed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, yes, let's keep it

this.hot = this.options.hot || this.options.hotOnly;
this.headers = this.options.headers;
this.progress = this.options.progress;

Expand Down Expand Up @@ -732,7 +737,7 @@ class Server {
this.sockWrite([connection], 'log-level', this.clientLogLevel);
}

if (this.hot) {
if (this.options.hot === true || this.options.hot === 'only') {
this.sockWrite([connection], 'hot');
}

Expand Down
15 changes: 9 additions & 6 deletions lib/options.json
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,14 @@
]
},
"hot": {
"type": "boolean"
},
"hotOnly": {
"type": "boolean"
"anyOf": [
{
"type": "boolean"
},
{
"enum": ["only"]
}
]
},
"http2": {
"type": "boolean"
Expand Down Expand Up @@ -446,8 +450,7 @@
"headers": "should be {Object} (https://webpack.js.org/configuration/dev-server/#devserverheaders-)",
"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)",
"hot": "should be {Boolean|String} (https://webpack.js.org/configuration/dev-server/#devserverhot)",
"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 @@ -141,7 +141,7 @@ function addEntries(config, options, server) {

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

if (options.hot || options.hotOnly) {
if (options.hot || options.hot === 'only') {
config.plugins = config.plugins || [];
if (
!config.plugins.find(
Expand Down
6 changes: 0 additions & 6 deletions lib/utils/createConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,6 @@ function createConfig(config, argv, { port }) {
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;
}

// TODO https://github.com/webpack/webpack-dev-server/issues/616 (v4)
// We should prefer CLI arg under config, now we always prefer `clientLogLevel` from `devServer`
if (!options.clientLogLevel && argv.clientLogLevel) {
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 === true || options.hot === 'only') {
compilersWithoutHMR.forEach((compiler) => {
// addDevServerEntrypoints above should have added the plugin
// to the compiler options
Expand Down
8 changes: 6 additions & 2 deletions test/__snapshots__/Validation.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ exports[`Validation validation should fail validation for invalid \`contentBase\

exports[`Validation validation should fail validation for invalid \`hot\` configuration 1`] = `
"Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
- configuration.hot should be a boolean."
- configuration.hot should be one of these:
boolean | \\"only\\"
Details:
* configuration.hot should be a boolean.
* configuration.hot should be \\"only\\"."
`;

exports[`Validation validation should fail validation for invalid \`logLevel\` configuration 1`] = `
Expand All @@ -33,5 +37,5 @@ exports[`Validation validation should fail validation for invalid \`writeToDisk\
exports[`Validation validation should fail validation for no additional properties 1`] = `
"Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
- configuration has an unknown property 'additional'. These properties are valid:
object { after?, allowedHosts?, before?, bonjour?, ca?, cert?, clientLogLevel?, compress?, contentBasePublicPath?, contentBase?, disableHostCheck?, features?, filename?, fs?, headers?, historyApiFallback?, host?, hot?, hotOnly?, http2?, https?, index?, injectClient?, injectHot?, inline?, key?, lazy?, liveReload?, log?, logLevel?, logTime?, mimeTypes?, noInfo?, onListening?, open?, openPage?, overlay?, pfx?, pfxPassphrase?, port?, profile?, progress?, proxy?, public?, publicPath?, quiet?, reporter?, requestCert?, serveIndex?, serverSideRender?, setup?, sockHost?, sockPath?, sockPort?, socket?, staticOptions?, stats?, transportMode?, useLocalIp?, warn?, watchContentBase?, watchOptions?, writeToDisk? }"
object { after?, allowedHosts?, before?, bonjour?, ca?, cert?, clientLogLevel?, compress?, contentBasePublicPath?, contentBase?, disableHostCheck?, features?, filename?, fs?, headers?, historyApiFallback?, host?, hot?, http2?, https?, index?, injectClient?, injectHot?, inline?, key?, lazy?, liveReload?, log?, logLevel?, logTime?, mimeTypes?, noInfo?, onListening?, open?, openPage?, overlay?, pfx?, pfxPassphrase?, port?, profile?, progress?, proxy?, public?, publicPath?, quiet?, reporter?, requestCert?, serveIndex?, serverSideRender?, setup?, sockHost?, sockPath?, sockPort?, socket?, staticOptions?, stats?, transportMode?, useLocalIp?, warn?, watchContentBase?, watchOptions?, writeToDisk? }"
`;
19 changes: 9 additions & 10 deletions test/e2e/Client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,11 @@ describe('reload', () => {
const modes = [
{
title: 'hot with default transportMode.client (sockjs)',
options: {
hot: true,
},
shouldRefresh: false,
},
{
title: 'hot with transportMode.client ws',
options: {
hot: true,
transportMode: 'ws',
},
shouldRefresh: false,
Expand Down Expand Up @@ -110,15 +106,18 @@ describe('reload', () => {
const bgColor = getComputedStyle(body)[
'background-color'
];

return bgColor;
})
.then((color2) => {
browser.close().then(() => {
expect(color).toEqual('rgb(0, 0, 255)');
expect(color2).toEqual('rgb(255, 0, 0)');
expect(refreshed).toEqual(mode.shouldRefresh);
done();
});
expect(color).toEqual('rgb(0, 0, 255)');
expect(color2).toEqual('rgb(255, 0, 0)');
expect(refreshed).toEqual(mode.shouldRefresh);

return browser.close();
})
.then(() => {
done();
});
});
});
Expand Down
3 changes: 3 additions & 0 deletions test/e2e/TransportMode.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,21 @@ describe('transportMode client', () => {
{
title: 'sockjs',
options: {
hot: false,
Copy link
Member Author

@hiroppy hiroppy Apr 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test has been set the value as false from before.(currently, we set the default value as true so we need to add this option to here)

transportMode: 'sockjs',
},
},
{
title: 'ws',
options: {
hot: false,
transportMode: 'ws',
},
},
{
title: 'custom client',
options: {
hot: false,
transportMode: {
server: 'sockjs',
client: require.resolve(
Expand Down
4 changes: 4 additions & 0 deletions test/e2e/__snapshots__/ClientOptions.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,16 @@ Array [
exports[`Client console.log liveReload disabled 1`] = `
Array [
"Hey.",
"[HMR] Waiting for update signal from WDS...",
"[WDS] Hot Module Replacement enabled.",
]
`;

exports[`Client console.log liveReload enabled 1`] = `
Array [
"Hey.",
"[HMR] Waiting for update signal from WDS...",
"[WDS] Hot Module Replacement enabled.",
"[WDS] Live Reloading enabled.",
]
`;
4 changes: 4 additions & 0 deletions test/e2e/__snapshots__/Iframe.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,16 @@ Array [
exports[`Client iframe console.log liveReload disabled 1`] = `
Array [
"Hey.",
"[HMR] Waiting for update signal from WDS...",
"[WDS] Hot Module Replacement enabled.",
]
`;

exports[`Client iframe console.log liveReload enabled 1`] = `
Array [
"Hey.",
"[HMR] Waiting for update signal from WDS...",
"[WDS] Hot Module Replacement enabled.",
"[WDS] Live Reloading enabled.",
]
`;
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
8 changes: 2 additions & 6 deletions test/options.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,8 @@ describe('options', () => {
failure: [false],
},
hot: {
success: [true],
failure: [''],
},
hotOnly: {
success: [true],
failure: [''],
success: [true, 'only'],
failure: ['', 'foo'],
},
http2: {
success: [true],
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 @@ -50,12 +50,12 @@ describe('Server', () => {
compiler.run(() => {});
});

it('add hotOnly option', (done) => {
it('add hot-only 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-only option 1`] = `
Array [
Array [
"client",
Expand Down
13 changes: 11 additions & 2 deletions test/server/__snapshots__/transportMode-option.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ Array [
Object {
"foo": "bar",
},
"{\\"type\\":\\"liveReload\\"}",
"{\\"type\\":\\"hot\\"}",
]
`;

Expand All @@ -96,11 +96,20 @@ Array [
Object {
"foo": "bar",
},
"{\\"type\\":\\"ok\\"}",
"{\\"type\\":\\"liveReload\\"}",
]
`;

exports[`transportMode server server should use server implementation correctly 5`] = `
Array [
Object {
"foo": "bar",
},
"{\\"type\\":\\"ok\\"}",
]
`;

exports[`transportMode server server should use server implementation correctly 6`] = `
Array [
Array [
Object {
Expand Down
27 changes: 23 additions & 4 deletions test/server/hot-option.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ describe('hot option', () => {
const options = {
port,
inline: true,
hot: true,
watchOptions: {
poll: true,
},
Expand All @@ -31,12 +30,34 @@ describe('hot option', () => {
});
});

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', (done) => {
req
.get('/main.js')
.expect(200, /webpack\/hot\/only-dev-server\.js/, done);
});
});

describe('multi compiler hot config entries', () => {
beforeAll((done) => {
const options = {
port,
inline: true,
hot: true,
watchOptions: {
poll: true,
},
Expand Down Expand Up @@ -92,7 +113,6 @@ describe('hot option', () => {
const options = {
port,
inline: true,
hot: true,
watchOptions: {
poll: true,
},
Expand Down Expand Up @@ -126,7 +146,6 @@ describe('hot option', () => {
const options = {
port,
inline: true,
hot: true,
watchOptions: {
poll: true,
},
Expand Down