diff --git a/bin/cli-flags.js b/bin/cli-flags.js index 153e0b353f..c489acf063 100644 --- a/bin/cli-flags.js +++ b/bin/cli-flags.js @@ -349,10 +349,17 @@ module.exports = { host: { configs: [ { - type: "string", + description: "Allows to specify a hostname to use.", multiple: false, + path: "host", + type: "enum", + values: ["local-ip", "local-ipv4", "local-ipv6"], + }, + { description: "Allows to specify a hostname to use.", + multiple: false, path: "host", + type: "string", }, ], description: "Allows to specify a hostname to use.", diff --git a/lib/options.json b/lib/options.json index b35816ecb9..fe1cbce6db 100644 --- a/lib/options.json +++ b/lib/options.json @@ -283,10 +283,17 @@ "link": "https://webpack.js.org/configuration/dev-server/#devserverhistoryapifallback" }, "Host": { - "type": "string", - "minLength": 1, "description": "Allows to specify a hostname to use.", - "link": "https://webpack.js.org/configuration/dev-server/#devserverhost" + "link": "https://webpack.js.org/configuration/dev-server/#devserverhost", + "anyOf": [ + { + "enum": ["local-ip", "local-ipv4", "local-ipv6"] + }, + { + "type": "string", + "minLength": 1 + } + ] }, "Hot": { "anyOf": [ diff --git a/test/__snapshots__/validate-options.test.js.snap.webpack4 b/test/__snapshots__/validate-options.test.js.snap.webpack4 index 69740b58e3..9065f5b7a3 100644 --- a/test/__snapshots__/validate-options.test.js.snap.webpack4 +++ b/test/__snapshots__/validate-options.test.js.snap.webpack4 @@ -258,23 +258,31 @@ exports[`options validate should throw an error on the "historyApiFallback" opti exports[`options validate should throw an error on the "host" option with '' value 1`] = ` "ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema. - - options.host should be a non-empty string. - -> Allows to specify a hostname to use. - -> Read more at https://webpack.js.org/configuration/dev-server/#devserverhost" + - options.host should be a non-empty string." `; exports[`options validate should throw an error on the "host" option with 'false' value 1`] = ` "ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema. - - options.host should be a non-empty string. + - options.host should be one of these: + \\"local-ip\\" | \\"local-ipv4\\" | \\"local-ipv6\\" | non-empty string -> Allows to specify a hostname to use. - -> Read more at https://webpack.js.org/configuration/dev-server/#devserverhost" + -> Read more at https://webpack.js.org/configuration/dev-server/#devserverhost + Details: + * options.host should be one of these: + \\"local-ip\\" | \\"local-ipv4\\" | \\"local-ipv6\\" + * options.host should be a non-empty string." `; exports[`options validate should throw an error on the "host" option with 'null' value 1`] = ` "ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema. - - options.host should be a non-empty string. + - options.host should be one of these: + \\"local-ip\\" | \\"local-ipv4\\" | \\"local-ipv6\\" | non-empty string -> Allows to specify a hostname to use. - -> Read more at https://webpack.js.org/configuration/dev-server/#devserverhost" + -> Read more at https://webpack.js.org/configuration/dev-server/#devserverhost + Details: + * options.host should be one of these: + \\"local-ip\\" | \\"local-ipv4\\" | \\"local-ipv6\\" + * options.host should be a non-empty string." `; exports[`options validate should throw an error on the "hot" option with '' value 1`] = ` diff --git a/test/__snapshots__/validate-options.test.js.snap.webpack5 b/test/__snapshots__/validate-options.test.js.snap.webpack5 index 69740b58e3..9065f5b7a3 100644 --- a/test/__snapshots__/validate-options.test.js.snap.webpack5 +++ b/test/__snapshots__/validate-options.test.js.snap.webpack5 @@ -258,23 +258,31 @@ exports[`options validate should throw an error on the "historyApiFallback" opti exports[`options validate should throw an error on the "host" option with '' value 1`] = ` "ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema. - - options.host should be a non-empty string. - -> Allows to specify a hostname to use. - -> Read more at https://webpack.js.org/configuration/dev-server/#devserverhost" + - options.host should be a non-empty string." `; exports[`options validate should throw an error on the "host" option with 'false' value 1`] = ` "ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema. - - options.host should be a non-empty string. + - options.host should be one of these: + \\"local-ip\\" | \\"local-ipv4\\" | \\"local-ipv6\\" | non-empty string -> Allows to specify a hostname to use. - -> Read more at https://webpack.js.org/configuration/dev-server/#devserverhost" + -> Read more at https://webpack.js.org/configuration/dev-server/#devserverhost + Details: + * options.host should be one of these: + \\"local-ip\\" | \\"local-ipv4\\" | \\"local-ipv6\\" + * options.host should be a non-empty string." `; exports[`options validate should throw an error on the "host" option with 'null' value 1`] = ` "ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema. - - options.host should be a non-empty string. + - options.host should be one of these: + \\"local-ip\\" | \\"local-ipv4\\" | \\"local-ipv6\\" | non-empty string -> Allows to specify a hostname to use. - -> Read more at https://webpack.js.org/configuration/dev-server/#devserverhost" + -> Read more at https://webpack.js.org/configuration/dev-server/#devserverhost + Details: + * options.host should be one of these: + \\"local-ip\\" | \\"local-ipv4\\" | \\"local-ipv6\\" + * options.host should be a non-empty string." `; exports[`options validate should throw an error on the "hot" option with '' value 1`] = `