diff --git a/bin/cli-flags.js b/bin/cli-flags.js index 973cee7ae0..4844923489 100644 --- a/bin/cli-flags.js +++ b/bin/cli-flags.js @@ -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', diff --git a/bin/options.js b/bin/options.js index 276468c2c3..f1225933dc 100644 --- a/bin/options.js +++ b/bin/options.js @@ -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: { diff --git a/lib/Server.js b/lib/Server.js index f4b3088ee8..d16732bc96 100644 --- a/lib/Server.js +++ b/lib/Server.js @@ -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 diff --git a/lib/options.json b/lib/options.json index 3f303842ee..55121fcbe0 100644 --- a/lib/options.json +++ b/lib/options.json @@ -114,10 +114,14 @@ ] }, "hot": { - "type": "boolean" - }, - "hotOnly": { - "type": "boolean" + "anyOf": [ + { + "type": "boolean" + }, + { + "enum": ["only"] + } + ] }, "http2": { "type": "boolean" @@ -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)", diff --git a/lib/utils/addEntries.js b/lib/utils/addEntries.js index 501b12e080..95b3dcb932 100644 --- a/lib/utils/addEntries.js +++ b/lib/utils/addEntries.js @@ -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'); @@ -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( diff --git a/lib/utils/createConfig.js b/lib/utils/createConfig.js index afc356f23a..6f50410a37 100644 --- a/lib/utils/createConfig.js +++ b/lib/utils/createConfig.js @@ -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) diff --git a/lib/utils/updateCompiler.js b/lib/utils/updateCompiler.js index 9f701e81b4..0687795044 100644 --- a/lib/utils/updateCompiler.js +++ b/lib/utils/updateCompiler.js @@ -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 diff --git a/test/__snapshots__/validate-options.test.js.snap b/test/__snapshots__/validate-options.test.js.snap index 16af1e32d3..35c9f2c538 100644 --- a/test/__snapshots__/validate-options.test.js.snap +++ b/test/__snapshots__/validate-options.test.js.snap @@ -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`] = ` diff --git a/test/fixtures/schema/webpack.config.no-dev-stats.js b/test/fixtures/schema/webpack.config.no-dev-stats.js index ca5a83b7da..553607cbe9 100644 --- a/test/fixtures/schema/webpack.config.no-dev-stats.js +++ b/test/fixtures/schema/webpack.config.no-dev-stats.js @@ -13,7 +13,6 @@ module.exports = { publicPath: '_publicPath', filename: '_filename', hot: '_hot', - hotOnly: '_hotOnly', clientLogLevel: '_clientLogLevel', contentBase: '_contentBase', watchContentBase: '_watchContentBase', diff --git a/test/helpers/test-server.js b/test/helpers/test-server.js index 85de3777f7..a72587436f 100644 --- a/test/helpers/test-server.js +++ b/test/helpers/test-server.js @@ -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; diff --git a/test/ports-map.js b/test/ports-map.js index 07ebee36a0..96300c3adc 100644 --- a/test/ports-map.js +++ b/test/ports-map.js @@ -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, diff --git a/test/server/Server.test.js b/test/server/Server.test.js index 81ea4803c5..8adf8cdcbb 100644 --- a/test/server/Server.test.js +++ b/test/server/Server.test.js @@ -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', }) ); diff --git a/test/server/__snapshots__/Server.test.js.snap b/test/server/__snapshots__/Server.test.js.snap index cd9adefb2c..e92e29d4fd 100644 --- a/test/server/__snapshots__/Server.test.js.snap +++ b/test/server/__snapshots__/Server.test.js.snap @@ -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", diff --git a/test/server/hot-option.test.js b/test/server/hot-option.test.js index e79679ff4b..ec13746aee 100644 --- a/test/server/hot-option.test.js +++ b/test/server/hot-option.test.js @@ -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); + }); }); diff --git a/test/server/hotOnly-option.test.js b/test/server/hotOnly-option.test.js deleted file mode 100644 index 61cba1eb88..0000000000 --- a/test/server/hotOnly-option.test.js +++ /dev/null @@ -1,68 +0,0 @@ -'use strict'; - -const request = require('supertest'); -const testServer = require('../helpers/test-server'); -const config = require('../fixtures/client-config/webpack.config'); -const port = require('../ports-map')['hotOnly-option']; - -describe('hotOnly options', () => { - let server; - let req; - - describe('simple hotOnly config entries', () => { - beforeAll((done) => { - const options = { - port, - inline: true, - hotOnly: true, - watchOptions: { - poll: true, - }, - }; - server = testServer.startAwaitingCompilation(config, options, done); - req = request(server.app); - }); - - afterAll(testServer.close); - - it('should include hotOnly script in the bundle', async () => { - await req - .get('/main.js') - .expect(200, /webpack\/hot\/only-dev-server\.js/); - }); - }); - - describe('simple hotOnly config HMR plugin', () => { - it('should register the HMR plugin before compilation is complete', (done) => { - let pluginFound = false; - const options = { - port, - inline: true, - hotOnly: true, - 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); - }); -}); diff --git a/test/server/open-option.test.js b/test/server/open-option.test.js index 01f7d88b8a..76658eb35c 100644 --- a/test/server/open-option.test.js +++ b/test/server/open-option.test.js @@ -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, }, diff --git a/test/server/servers/__snapshots__/WebsocketServer.test.js.snap b/test/server/servers/__snapshots__/WebsocketServer.test.js.snap index 2722e7f517..a588c506f7 100644 --- a/test/server/servers/__snapshots__/WebsocketServer.test.js.snap +++ b/test/server/servers/__snapshots__/WebsocketServer.test.js.snap @@ -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 [ diff --git a/test/server/utils/__snapshots__/createConfig.test.js.snap b/test/server/utils/__snapshots__/createConfig.test.js.snap index dd2215151b..a6d4eed9ff 100644 --- a/test/server/utils/__snapshots__/createConfig.test.js.snap +++ b/test/server/utils/__snapshots__/createConfig.test.js.snap @@ -7,7 +7,6 @@ Object { "host2.com", ], "hot": true, - "hotOnly": false, "noInfo": true, "port": 8080, "publicPath": "/", @@ -25,7 +24,6 @@ Object { "host2.com", ], "hot": true, - "hotOnly": false, "noInfo": true, "port": 8080, "publicPath": "/", @@ -40,7 +38,6 @@ exports[`createConfig bonjour option (devServer config) 1`] = ` Object { "bonjour": true, "hot": true, - "hotOnly": false, "noInfo": true, "port": 8080, "publicPath": "/", @@ -55,7 +52,6 @@ exports[`createConfig bonjour option 1`] = ` Object { "bonjour": true, "hot": true, - "hotOnly": false, "noInfo": true, "port": 8080, "publicPath": "/", @@ -70,7 +66,6 @@ exports[`createConfig cacert option (in devServer config) 1`] = ` Object { "ca": "/path/to/ca.pem", "hot": true, - "hotOnly": false, "https": true, "noInfo": true, "port": 8080, @@ -86,7 +81,6 @@ exports[`createConfig cacert option 1`] = ` Object { "ca": "/path/to/ca.pem", "hot": true, - "hotOnly": false, "https": true, "noInfo": true, "port": 8080, @@ -102,7 +96,6 @@ exports[`createConfig cert option (in devServer config) 1`] = ` Object { "cert": "/path/to/server.crt", "hot": true, - "hotOnly": false, "https": true, "noInfo": true, "port": 8080, @@ -118,7 +111,6 @@ exports[`createConfig cert option 1`] = ` Object { "cert": "/path/to/server.crt", "hot": true, - "hotOnly": false, "https": true, "noInfo": true, "port": 8080, @@ -134,7 +126,6 @@ exports[`createConfig clientLogLevel option (in devServer config) 1`] = ` Object { "clientLogLevel": "none", "hot": true, - "hotOnly": false, "noInfo": true, "port": 8080, "publicPath": "/", @@ -149,7 +140,6 @@ exports[`createConfig clientLogLevel option 1`] = ` Object { "clientLogLevel": "none", "hot": true, - "hotOnly": false, "noInfo": true, "port": 8080, "publicPath": "/", @@ -164,7 +154,6 @@ exports[`createConfig compress option (in devServer config) 1`] = ` Object { "compress": true, "hot": true, - "hotOnly": false, "noInfo": true, "port": 8080, "publicPath": "/", @@ -179,7 +168,6 @@ exports[`createConfig compress option 1`] = ` Object { "compress": true, "hot": true, - "hotOnly": false, "noInfo": true, "port": 8080, "publicPath": "/", @@ -197,7 +185,6 @@ Object { "static", ], "hot": true, - "hotOnly": false, "noInfo": true, "port": 8080, "publicPath": "/", @@ -212,7 +199,6 @@ exports[`createConfig contentBase option (boolean) 1`] = ` Object { "contentBase": false, "hot": true, - "hotOnly": false, "noInfo": true, "port": 8080, "publicPath": "/", @@ -227,7 +213,6 @@ exports[`createConfig contentBase option (string) (in devServer config) 1`] = ` Object { "contentBase": "assets", "hot": true, - "hotOnly": false, "noInfo": true, "port": 8080, "publicPath": "/", @@ -242,7 +227,6 @@ exports[`createConfig contentBase option (string) 1`] = ` Object { "contentBase": "assets", "hot": true, - "hotOnly": false, "noInfo": true, "port": 8080, "publicPath": "/", @@ -257,7 +241,6 @@ exports[`createConfig disableHostCheck option (in devServer config) 1`] = ` Object { "disableHostCheck": true, "hot": true, - "hotOnly": false, "noInfo": true, "port": 8080, "publicPath": "/", @@ -272,7 +255,6 @@ exports[`createConfig disableHostCheck option 1`] = ` Object { "disableHostCheck": true, "hot": true, - "hotOnly": false, "noInfo": true, "port": 8080, "publicPath": "/", @@ -287,7 +269,6 @@ exports[`createConfig filename option (in devServer config) 1`] = ` Object { "filename": "[name]-dev-server-bundle.js", "hot": true, - "hotOnly": false, "noInfo": true, "port": 8080, "publicPath": "/", @@ -302,7 +283,6 @@ exports[`createConfig filename option (in output config) 1`] = ` Object { "filename": "[name]-output-bundle.js", "hot": true, - "hotOnly": false, "noInfo": true, "port": 8080, "publicPath": "/", @@ -317,7 +297,6 @@ exports[`createConfig filename option (in webpack config) 1`] = ` Object { "filename": "[name]-bundle.js", "hot": true, - "hotOnly": false, "noInfo": true, "port": 8080, "publicPath": "/", @@ -332,7 +311,6 @@ exports[`createConfig historyApiFallback option (in devServer config) 1`] = ` Object { "historyApiFallback": true, "hot": true, - "hotOnly": false, "noInfo": true, "port": 8080, "publicPath": "/", @@ -347,7 +325,6 @@ exports[`createConfig historyApiFallback option 1`] = ` Object { "historyApiFallback": true, "hot": true, - "hotOnly": false, "noInfo": true, "port": 8080, "publicPath": "/", @@ -362,7 +339,6 @@ exports[`createConfig host option (devServer config) 1`] = ` Object { "host": "example.dev", "hot": true, - "hotOnly": false, "noInfo": true, "port": 8080, "publicPath": "/", @@ -377,7 +353,6 @@ exports[`createConfig host option (localhost) 1`] = ` Object { "host": "localhost", "hot": true, - "hotOnly": false, "noInfo": true, "port": 8080, "publicPath": "/", @@ -391,7 +366,6 @@ Object { exports[`createConfig host option (null) 1`] = ` Object { "hot": true, - "hotOnly": false, "noInfo": true, "port": 8080, "publicPath": "/", @@ -406,7 +380,6 @@ exports[`createConfig host option (specify for CLI and devServer config) 1`] = ` Object { "host": "other.dev", "hot": true, - "hotOnly": false, "noInfo": true, "port": 8080, "publicPath": "/", @@ -420,7 +393,6 @@ Object { exports[`createConfig host option (undefined) 1`] = ` Object { "hot": true, - "hotOnly": false, "noInfo": true, "port": 8080, "publicPath": "/", @@ -435,7 +407,6 @@ exports[`createConfig host option 1`] = ` Object { "host": "example.dev", "hot": true, - "hotOnly": false, "noInfo": true, "port": 8080, "publicPath": "/", @@ -446,10 +417,9 @@ Object { } `; -exports[`createConfig hot option (in devServer config) 1`] = ` +exports[`createConfig hot only option (in devServer config) 1`] = ` Object { - "hot": true, - "hotOnly": false, + "hot": "only", "noInfo": true, "port": 8080, "publicPath": "/", @@ -460,10 +430,9 @@ Object { } `; -exports[`createConfig hot option 1`] = ` +exports[`createConfig hot only option 1`] = ` Object { - "hot": true, - "hotOnly": false, + "hot": "only", "noInfo": true, "port": 8080, "publicPath": "/", @@ -474,10 +443,9 @@ Object { } `; -exports[`createConfig hotOnly option (in devServer config) 1`] = ` +exports[`createConfig hot option (in devServer config) 1`] = ` Object { "hot": true, - "hotOnly": true, "noInfo": true, "port": 8080, "publicPath": "/", @@ -488,10 +456,9 @@ Object { } `; -exports[`createConfig hotOnly option 1`] = ` +exports[`createConfig hot option 1`] = ` Object { "hot": true, - "hotOnly": true, "noInfo": true, "port": 8080, "publicPath": "/", @@ -505,7 +472,6 @@ Object { exports[`createConfig http2 option (in devServer config) 1`] = ` Object { "hot": true, - "hotOnly": false, "http2": true, "https": true, "noInfo": true, @@ -521,7 +487,6 @@ Object { exports[`createConfig http2 option 1`] = ` Object { "hot": true, - "hotOnly": false, "http2": true, "https": true, "noInfo": true, @@ -537,7 +502,6 @@ Object { exports[`createConfig https option (in devServer config) 1`] = ` Object { "hot": true, - "hotOnly": false, "https": true, "noInfo": true, "port": 8080, @@ -552,7 +516,6 @@ Object { exports[`createConfig https option (in devServer config) 2`] = ` Object { "hot": true, - "hotOnly": false, "noInfo": true, "pfxPassphrase": "passphrase", "port": 8080, @@ -567,7 +530,6 @@ Object { exports[`createConfig https option 1`] = ` Object { "hot": true, - "hotOnly": false, "https": true, "noInfo": true, "port": 8080, @@ -582,7 +544,6 @@ Object { exports[`createConfig info option (in devServer config) 1`] = ` Object { "hot": true, - "hotOnly": false, "noInfo": true, "port": 8080, "publicPath": "/", @@ -596,7 +557,6 @@ Object { exports[`createConfig info option 1`] = ` Object { "hot": true, - "hotOnly": false, "noInfo": true, "port": 8080, "publicPath": "/", @@ -610,7 +570,6 @@ Object { exports[`createConfig inline option (in devServer config) 1`] = ` Object { "hot": true, - "hotOnly": false, "inline": false, "noInfo": true, "port": 8080, @@ -625,7 +584,6 @@ Object { exports[`createConfig inline option 1`] = ` Object { "hot": true, - "hotOnly": false, "inline": false, "noInfo": true, "port": 8080, @@ -640,7 +598,6 @@ Object { exports[`createConfig key option (in devServer config) 1`] = ` Object { "hot": true, - "hotOnly": false, "https": true, "key": "/path/to/server.key", "noInfo": true, @@ -656,7 +613,6 @@ Object { exports[`createConfig key option 1`] = ` Object { "hot": true, - "hotOnly": false, "https": true, "key": "/path/to/server.key", "noInfo": true, @@ -672,7 +628,6 @@ Object { exports[`createConfig lazy option (in devServer config) 1`] = ` Object { "hot": true, - "hotOnly": false, "lazy": true, "noInfo": true, "port": 8080, @@ -687,7 +642,6 @@ Object { exports[`createConfig lazy option 1`] = ` Object { "hot": true, - "hotOnly": false, "lazy": true, "noInfo": true, "port": 8080, @@ -702,7 +656,6 @@ Object { exports[`createConfig liveReload option 1`] = ` Object { "hot": true, - "hotOnly": false, "liveReload": false, "noInfo": true, "port": 8080, @@ -717,7 +670,6 @@ Object { exports[`createConfig mimeTypes option - with force 1`] = ` Object { "hot": true, - "hotOnly": false, "mimeTypes": Object { "force": true, "typeMap": Object { @@ -739,7 +691,6 @@ Object { exports[`createConfig mimeTypes option 1`] = ` Object { "hot": true, - "hotOnly": false, "mimeTypes": Object { "text/html": Array [ "phtml", @@ -758,7 +709,6 @@ Object { exports[`createConfig onListening option 1`] = ` Object { "hot": true, - "hotOnly": false, "noInfo": true, "onListening": [Function], "port": 8080, @@ -773,7 +723,6 @@ Object { exports[`createConfig open option (boolean) (in devServer config) 1`] = ` Object { "hot": true, - "hotOnly": false, "noInfo": true, "open": true, "openPage": "", @@ -789,7 +738,6 @@ Object { exports[`createConfig open option (boolean) 1`] = ` Object { "hot": true, - "hotOnly": false, "noInfo": true, "open": true, "openPage": "", @@ -805,7 +753,6 @@ Object { exports[`createConfig open option (browser) 1`] = ` Object { "hot": true, - "hotOnly": false, "noInfo": true, "open": "Google Chrome", "openPage": "", @@ -821,7 +768,6 @@ Object { exports[`createConfig openPage multiple option (in devServer config) 1`] = ` Object { "hot": true, - "hotOnly": false, "noInfo": true, "open": true, "openPage": Array [ @@ -840,7 +786,6 @@ Object { exports[`createConfig openPage option (in devServer config) 1`] = ` Object { "hot": true, - "hotOnly": false, "noInfo": true, "open": true, "openPage": "/different/page", @@ -856,7 +801,6 @@ Object { exports[`createConfig openPage option 1`] = ` Object { "hot": true, - "hotOnly": false, "noInfo": true, "open": true, "openPage": Array [ @@ -874,7 +818,6 @@ Object { exports[`createConfig overlay option (in devServer config) 1`] = ` Object { "hot": true, - "hotOnly": false, "noInfo": true, "overlay": true, "port": 8080, @@ -889,7 +832,6 @@ Object { exports[`createConfig overlay option 1`] = ` Object { "hot": true, - "hotOnly": false, "noInfo": true, "overlay": true, "port": 8080, @@ -904,7 +846,6 @@ Object { exports[`createConfig pfx option (in devServer config) 1`] = ` Object { "hot": true, - "hotOnly": false, "https": true, "noInfo": true, "pfx": "/path/to/file.pfx", @@ -920,7 +861,6 @@ Object { exports[`createConfig pfx option 1`] = ` Object { "hot": true, - "hotOnly": false, "https": true, "noInfo": true, "pfx": "/path/to/file.pfx", @@ -936,7 +876,6 @@ Object { exports[`createConfig pfxPassphrase option 1`] = ` Object { "hot": true, - "hotOnly": false, "noInfo": true, "pfxPassphrase": "passphrase", "port": 8080, @@ -951,7 +890,6 @@ Object { exports[`createConfig port option (difference) 1`] = ` Object { "hot": true, - "hotOnly": false, "noInfo": true, "port": 7070, "publicPath": "/", @@ -965,7 +903,6 @@ Object { exports[`createConfig port option (same) (null) 1`] = ` Object { "hot": true, - "hotOnly": false, "noInfo": true, "port": null, "publicPath": "/", @@ -979,7 +916,6 @@ Object { exports[`createConfig port option (same) (string) 1`] = ` Object { "hot": true, - "hotOnly": false, "noInfo": true, "port": "9090", "publicPath": "/", @@ -993,7 +929,6 @@ Object { exports[`createConfig port option (same) (undefined) 1`] = ` Object { "hot": true, - "hotOnly": false, "noInfo": true, "port": undefined, "publicPath": "/", @@ -1007,7 +942,6 @@ Object { exports[`createConfig port option (same) 1`] = ` Object { "hot": true, - "hotOnly": false, "noInfo": true, "port": 9090, "publicPath": "/", @@ -1021,7 +955,6 @@ Object { exports[`createConfig profile option 1`] = ` Object { "hot": true, - "hotOnly": false, "noInfo": true, "port": 8080, "profile": "profile", @@ -1036,7 +969,6 @@ Object { exports[`createConfig progress option (devServer config) 1`] = ` Object { "hot": true, - "hotOnly": false, "noInfo": true, "port": 8080, "progress": true, @@ -1051,7 +983,6 @@ Object { exports[`createConfig progress option 1`] = ` Object { "hot": true, - "hotOnly": false, "noInfo": true, "port": 8080, "progress": true, @@ -1066,7 +997,6 @@ Object { exports[`createConfig public option (devServer config) 1`] = ` Object { "hot": true, - "hotOnly": false, "noInfo": true, "port": 8080, "public": true, @@ -1081,7 +1011,6 @@ Object { exports[`createConfig public option 1`] = ` Object { "hot": true, - "hotOnly": false, "noInfo": true, "port": 8080, "public": true, @@ -1096,7 +1025,6 @@ Object { exports[`createConfig publicPath option (not specify) 1`] = ` Object { "hot": true, - "hotOnly": false, "noInfo": true, "port": 8080, "publicPath": "/", @@ -1110,7 +1038,6 @@ Object { exports[`createConfig publicPath option (path in devServer option) 1`] = ` Object { "hot": true, - "hotOnly": false, "noInfo": true, "port": 8080, "publicPath": "/assets/", @@ -1124,7 +1051,6 @@ Object { exports[`createConfig publicPath option (path in output option) 1`] = ` Object { "hot": true, - "hotOnly": false, "noInfo": true, "port": 8080, "publicPath": "/assets/", @@ -1138,7 +1064,6 @@ Object { exports[`createConfig publicPath option (path without starting slash in output option) 1`] = ` Object { "hot": true, - "hotOnly": false, "noInfo": true, "port": 8080, "publicPath": "/assets/", @@ -1152,7 +1077,6 @@ Object { exports[`createConfig publicPath option (url in devServer option) 1`] = ` Object { "hot": true, - "hotOnly": false, "noInfo": true, "port": 8080, "publicPath": "http://localhost:8080/assets/", @@ -1166,7 +1090,6 @@ Object { exports[`createConfig publicPath option (url in output option) 1`] = ` Object { "hot": true, - "hotOnly": false, "noInfo": true, "port": 8080, "publicPath": "http://localhost:8080/assets/", @@ -1180,7 +1103,6 @@ Object { exports[`createConfig quiet option (in devServer config) 1`] = ` Object { "hot": true, - "hotOnly": false, "noInfo": true, "port": 8080, "publicPath": "/", @@ -1195,7 +1117,6 @@ Object { exports[`createConfig quiet option 1`] = ` Object { "hot": true, - "hotOnly": false, "noInfo": true, "port": 8080, "publicPath": "/", @@ -1210,7 +1131,6 @@ Object { exports[`createConfig simple 1`] = ` Object { "hot": true, - "hotOnly": false, "noInfo": true, "port": 8080, "publicPath": "/", @@ -1224,7 +1144,6 @@ Object { exports[`createConfig sockHost option 1`] = ` Object { "hot": true, - "hotOnly": false, "noInfo": true, "port": 8080, "publicPath": "/", @@ -1239,7 +1158,6 @@ Object { exports[`createConfig sockPath option 1`] = ` Object { "hot": true, - "hotOnly": false, "noInfo": true, "port": 8080, "publicPath": "/", @@ -1254,7 +1172,6 @@ Object { exports[`createConfig sockPort option 1`] = ` Object { "hot": true, - "hotOnly": false, "noInfo": true, "port": 8080, "publicPath": "/", @@ -1269,7 +1186,6 @@ Object { exports[`createConfig socket option (devServer config) 1`] = ` Object { "hot": true, - "hotOnly": false, "noInfo": true, "port": 8080, "publicPath": "/", @@ -1284,7 +1200,6 @@ Object { exports[`createConfig socket option 1`] = ` Object { "hot": true, - "hotOnly": false, "noInfo": true, "port": 8080, "publicPath": "/", @@ -1299,7 +1214,6 @@ Object { exports[`createConfig stats option (colors) 1`] = ` Object { "hot": true, - "hotOnly": false, "noInfo": true, "port": 8080, "publicPath": "/", @@ -1313,7 +1227,6 @@ Object { exports[`createConfig stats option 1`] = ` Object { "hot": true, - "hotOnly": false, "noInfo": true, "port": 8080, "publicPath": "/", @@ -1331,7 +1244,6 @@ Object { "historyApiFallback": "_historyApiFallback", "host": "_foo", "hot": "_hot", - "hotOnly": "_hotOnly", "https": "_https", "inline": "_inline", "lazy": "_lazy", @@ -1364,7 +1276,6 @@ Object { "historyApiFallback": "_historyApiFallback", "host": "_foo", "hot": "_hot", - "hotOnly": "_hotOnly", "https": "_https", "inline": "_inline", "lazy": "_lazy", @@ -1395,7 +1306,6 @@ Object { exports[`createConfig useLocalIp option (in devServer config) 1`] = ` Object { "hot": true, - "hotOnly": false, "noInfo": true, "port": 8080, "publicPath": "/", @@ -1410,7 +1320,6 @@ Object { exports[`createConfig useLocalIp option 1`] = ` Object { "hot": true, - "hotOnly": false, "noInfo": true, "port": 8080, "publicPath": "/", @@ -1425,7 +1334,6 @@ Object { exports[`createConfig watchContentBase option (in devServer config) 1`] = ` Object { "hot": true, - "hotOnly": false, "noInfo": true, "port": 8080, "publicPath": "/", @@ -1440,7 +1348,6 @@ Object { exports[`createConfig watchContentBase option 1`] = ` Object { "hot": true, - "hotOnly": false, "noInfo": true, "port": 8080, "publicPath": "/", @@ -1455,7 +1362,6 @@ Object { exports[`createConfig watchOptions option (in devServer config) 1`] = ` Object { "hot": true, - "hotOnly": false, "noInfo": true, "port": 8080, "publicPath": "/", @@ -1472,7 +1378,6 @@ Object { exports[`createConfig watchOptions option (in output config) 1`] = ` Object { "hot": true, - "hotOnly": false, "noInfo": true, "port": 8080, "publicPath": "/", diff --git a/test/server/utils/addEntries.test.js b/test/server/utils/addEntries.test.js index c124c7c36c..69984a7ad8 100644 --- a/test/server/utils/addEntries.test.js +++ b/test/server/utils/addEntries.test.js @@ -11,9 +11,8 @@ const normalize = (entry) => entry.split(path.sep).join('/'); describe('addEntries util', () => { it('should adds devServer entry points to a single entry point', () => { const webpackOptions = Object.assign({}, config); - const devServerOptions = {}; - addEntries(webpackOptions, devServerOptions); + addEntries(webpackOptions, {}); expect(webpackOptions.entry.length).toEqual(2); expect( @@ -27,9 +26,7 @@ describe('addEntries util', () => { entry: ['./foo.js', './bar.js'], }); - const devServerOptions = {}; - - addEntries(webpackOptions, devServerOptions); + addEntries(webpackOptions, {}); expect(webpackOptions.entry.length).toEqual(3); expect( @@ -47,9 +44,7 @@ describe('addEntries util', () => { }, }); - const devServerOptions = {}; - - addEntries(webpackOptions, devServerOptions); + addEntries(webpackOptions, {}); expect(webpackOptions.entry.foo.length).toEqual(2); @@ -62,9 +57,8 @@ describe('addEntries util', () => { it('should set defaults to src if no entry point is given', () => { const webpackOptions = {}; - const devServerOptions = {}; - addEntries(webpackOptions, devServerOptions); + addEntries(webpackOptions, {}); expect(webpackOptions.entry.length).toEqual(2); expect(webpackOptions.entry[1]).toEqual('./src'); @@ -79,9 +73,8 @@ describe('addEntries util', () => { return `./src-${i}.js`; }, }; - const devServerOptions = {}; - addEntries(webpackOptions, devServerOptions); + addEntries(webpackOptions, {}); expect(typeof webpackOptions.entry).toEqual('function'); @@ -110,9 +103,7 @@ describe('addEntries util', () => { }), }; - const devServerOptions = {}; - - addEntries(webpackOptions, devServerOptions); + addEntries(webpackOptions, {}); expect(typeof webpackOptions.entry).toEqual('function'); @@ -137,11 +128,7 @@ describe('addEntries util', () => { }, }); - const devServerOptions = { - hot: true, - }; - - addEntries(webpackOptions, devServerOptions); + addEntries(webpackOptions, { hot: true }); const hotClientScript = webpackOptions.entry.app[1]; @@ -151,18 +138,14 @@ describe('addEntries util', () => { expect(hotClientScript).toEqual(require.resolve(hotClientScript)); }); - it("should prepends webpack's hot-only client script", () => { + it("should prepends webpack's hot only client script", () => { const webpackOptions = Object.assign({}, config, { entry: { app: './app.js', }, }); - const devServerOptions = { - hotOnly: true, - }; - - addEntries(webpackOptions, devServerOptions); + addEntries(webpackOptions, { hot: 'only' }); const hotClientScript = webpackOptions.entry.app[1]; @@ -174,18 +157,16 @@ describe('addEntries util', () => { it("should doesn't add the HMR plugin if not hot and no plugins", () => { const webpackOptions = Object.assign({}, config); - const devServerOptions = {}; - addEntries(webpackOptions, devServerOptions); + addEntries(webpackOptions, {}); expect('plugins' in webpackOptions).toBeFalsy(); }); it("should doesn't add the HMR plugin if not hot and empty plugins", () => { const webpackOptions = Object.assign({}, config, { plugins: [] }); - const devServerOptions = {}; - addEntries(webpackOptions, devServerOptions); + addEntries(webpackOptions, {}); expect(webpackOptions.plugins).toEqual([]); }); @@ -196,9 +177,8 @@ describe('addEntries util', () => { const webpackOptions = Object.assign({}, config, { plugins: [existingPlugin1, existingPlugin2], }); - const devServerOptions = {}; - addEntries(webpackOptions, devServerOptions); + addEntries(webpackOptions, {}); expect(webpackOptions.plugins).toEqual([existingPlugin1, existingPlugin2]); }); @@ -208,9 +188,8 @@ describe('addEntries util', () => { const webpackOptions = Object.assign({}, config, { plugins: [existingPlugin], }); - const devServerOptions = { hot: true }; - addEntries(webpackOptions, devServerOptions); + addEntries(webpackOptions, { hot: true }); expect(webpackOptions.plugins).toEqual([ existingPlugin, @@ -220,9 +199,8 @@ describe('addEntries util', () => { it('should adds the HMR plugin if hot-only', () => { const webpackOptions = Object.assign({}, config); - const devServerOptions = { hotOnly: true }; - addEntries(webpackOptions, devServerOptions); + addEntries(webpackOptions, { hot: 'only' }); expect(webpackOptions.plugins).toEqual([ new webpack.HotModuleReplacementPlugin(), @@ -234,9 +212,8 @@ describe('addEntries util', () => { const webpackOptions = Object.assign({}, config, { plugins: [new webpack.HotModuleReplacementPlugin(), existingPlugin], }); - const devServerOptions = { hot: true }; - addEntries(webpackOptions, devServerOptions); + addEntries(webpackOptions, { hot: true }); expect(webpackOptions.plugins).toEqual([ new webpack.HotModuleReplacementPlugin(), @@ -253,9 +230,8 @@ describe('addEntries util', () => { const webpackOptions = Object.assign({}, config, { plugins: [new HotModuleReplacementPlugin(), existingPlugin], }); - const devServerOptions = { hot: true }; - addEntries(webpackOptions, devServerOptions); + addEntries(webpackOptions, { hot: true }); expect(webpackOptions.plugins).toEqual([ // Nothing should be injected @@ -266,10 +242,9 @@ describe('addEntries util', () => { it('should can prevent duplicate entries from successive calls', () => { const webpackOptions = Object.assign({}, config); - const devServerOptions = { hot: true }; - addEntries(webpackOptions, devServerOptions); - addEntries(webpackOptions, devServerOptions); + addEntries(webpackOptions, { hot: true }); + addEntries(webpackOptions, { hot: true }); expect(webpackOptions.entry.length).toEqual(3); @@ -281,9 +256,8 @@ describe('addEntries util', () => { it('should supports entry as Function', () => { const webpackOptions = Object.assign({}, configEntryAsFunction); - const devServerOptions = {}; - addEntries(webpackOptions, devServerOptions); + addEntries(webpackOptions, {}); expect(typeof webpackOptions.entry === 'function').toBe(true); }); @@ -298,9 +272,7 @@ describe('addEntries util', () => { Object.assign({ target: 'node' }, config) /* index:5 */, ]; - const devServerOptions = {}; - - addEntries(webpackOptions, devServerOptions); + addEntries(webpackOptions, {}); // eslint-disable-next-line no-shadow webpackOptions.forEach((webpackOptions, index) => { @@ -328,11 +300,9 @@ describe('addEntries util', () => { Object.assign({ target: 'node' }, config), ]; - const devServerOptions = { + addEntries(webpackOptions, { injectClient: (compilerConfig) => compilerConfig.name === 'only-include', - }; - - addEntries(webpackOptions, devServerOptions); + }); // eslint-disable-next-line no-shadow webpackOptions.forEach((webpackOptions, index) => { @@ -358,14 +328,12 @@ describe('addEntries util', () => { Object.assign({ target: 'node' }, config), ]; - const devServerOptions = { + addEntries(webpackOptions, { // disable inlining the client so entry indexes match up // and we can use the same assertions for both configs injectClient: false, hot: true, - }; - - addEntries(webpackOptions, devServerOptions); + }); // eslint-disable-next-line no-shadow webpackOptions.forEach((webpackOptions) => { @@ -385,12 +353,10 @@ describe('addEntries util', () => { Object.assign({ target: 'node' }, config), ]; - const devServerOptions = { + addEntries(webpackOptions, { injectHot: (compilerConfig) => compilerConfig.target === 'node', hot: true, - }; - - addEntries(webpackOptions, devServerOptions); + }); // node target should have the client runtime but not the hot runtime const webWebpackOptions = webpackOptions[0]; diff --git a/test/server/utils/createConfig.test.js b/test/server/utils/createConfig.test.js index 746b7dba64..ac7eae3b77 100644 --- a/test/server/utils/createConfig.test.js +++ b/test/server/utils/createConfig.test.js @@ -9,8 +9,6 @@ const argv = { port: 8080, // Can be `--no-hot` in CLI (undocumented) hot: true, - // Can be `--no-hot-only` in CLI (misleading and undocumented) - hotOnly: false, }; describe('createConfig', () => { @@ -358,20 +356,20 @@ describe('createConfig', () => { expect(config).toMatchSnapshot(); }); - it('hotOnly option', () => { + it('hot only option', () => { const config = createConfig( webpackConfig, - Object.assign({}, argv, { hotOnly: true }), + Object.assign({}, argv, { hot: 'only' }), { port: 8080 } ); expect(config).toMatchSnapshot(); }); - it('hotOnly option (in devServer config)', () => { + it('hot only option (in devServer config)', () => { const config = createConfig( Object.assign({}, webpackConfig, { - devServer: { hotOnly: true }, + devServer: { hot: 'only' }, }), argv, { port: 8080 } diff --git a/test/validate-options.test.js b/test/validate-options.test.js index f3f4724696..93e0d3b031 100644 --- a/test/validate-options.test.js +++ b/test/validate-options.test.js @@ -92,11 +92,7 @@ describe('options', () => { failure: [false], }, hot: { - success: [true], - failure: [''], - }, - hotOnly: { - success: [true], + success: [true, 'only'], failure: [''], }, http2: {