Skip to content

Commit 4831f58

Browse files
authored
feat: added magicHtml option (#3717)
1 parent 3a04c60 commit 4831f58

16 files changed

+422
-7
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ Options:
132132
--ipc [value] Listen to a unix socket.
133133
--live-reload Enables reload/refresh the page(s) when file changes are detected (enabled by default).
134134
--no-live-reload Negative 'live-reload' option.
135+
--magic-html Enables/Disables magic HTML routes (enabled by default).
136+
--no-magic-html Negative 'magic-html' option.
135137
--open [value...] Allows to configure dev server to open the browser(s) and page(s) after server had been started (set it to
136138
true to open your default browser).
137139
--no-open Negative 'open' option.

bin/cli-flags.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,19 @@ module.exports = {
534534
simpleType: "boolean",
535535
multiple: false,
536536
},
537+
"magic-html": {
538+
configs: [
539+
{
540+
type: "boolean",
541+
multiple: false,
542+
description: "Enables/Disables magic HTML routes (enabled by default).",
543+
path: "magicHtml",
544+
},
545+
],
546+
description: "Enables/Disables magic HTML routes (enabled by default).",
547+
simpleType: "boolean",
548+
multiple: false,
549+
},
537550
open: {
538551
configs: [
539552
{

lib/Server.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,9 @@ class Server {
431431
options.liveReload =
432432
typeof options.liveReload !== "undefined" ? options.liveReload : true;
433433

434+
options.magicHtml =
435+
typeof options.magicHtml !== "undefined" ? options.magicHtml : true;
436+
434437
// https://github.com/webpack/webpack-dev-server/issues/1990
435438
const defaultOpenOptions = { wait: false };
436439
const getOpenItemsFromObject = ({ target, ...rest }) => {
@@ -1132,7 +1135,9 @@ class Server {
11321135
runnableFeatures.push("staticServeIndex", "staticWatch");
11331136
}
11341137

1135-
runnableFeatures.push("magicHtml");
1138+
if (this.options.magicHtml) {
1139+
runnableFeatures.push("magicHtml");
1140+
}
11361141

11371142
if (this.options.onAfterSetupMiddleware) {
11381143
runnableFeatures.push("onAfterSetupMiddleware");

lib/options.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,11 @@
331331
"description": "Enables reload/refresh the page(s) when file changes are detected (enabled by default).",
332332
"link": "https://webpack.js.org/configuration/dev-server/#devserverlivereload"
333333
},
334+
"MagicHTML": {
335+
"type": "boolean",
336+
"description": "Enables/Disables magic HTML routes (enabled by default).",
337+
"link": "https://webpack.js.org/configuration/dev-server/#devservermagichtml"
338+
},
334339
"OnAfterSetupMiddleware": {
335340
"instanceof": "Function",
336341
"description": "Provides the ability to execute a custom function and apply custom middleware(s) after all other middlewares.",
@@ -729,6 +734,9 @@
729734
"liveReload": {
730735
"$ref": "#/definitions/LiveReload"
731736
},
737+
"magicHtml": {
738+
"$ref": "#/definitions/MagicHTML"
739+
},
732740
"onAfterSetupMiddleware": {
733741
"$ref": "#/definitions/OnAfterSetupMiddleware"
734742
},

test/__snapshots__/validate-options.test.js.snap.webpack4

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,13 @@ exports[`options validate should throw an error on the "liveReload" option with
439439
-> Read more at https://webpack.js.org/configuration/dev-server/#devserverlivereload"
440440
`;
441441

442+
exports[`options validate should throw an error on the "magicHtml" option with 'string' value 1`] = `
443+
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
444+
- options.magicHtml should be a boolean.
445+
-> Enables/Disables magic HTML routes (enabled by default).
446+
-> Read more at https://webpack.js.org/configuration/dev-server/#devservermagichtml"
447+
`;
448+
442449
exports[`options validate should throw an error on the "onAfterSetupMiddleware" option with 'false' value 1`] = `
443450
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
444451
- options.onAfterSetupMiddleware should be an instance of function.

test/__snapshots__/validate-options.test.js.snap.webpack5

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,13 @@ exports[`options validate should throw an error on the "liveReload" option with
439439
-> Read more at https://webpack.js.org/configuration/dev-server/#devserverlivereload"
440440
`;
441441

442+
exports[`options validate should throw an error on the "magicHtml" option with 'string' value 1`] = `
443+
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
444+
- options.magicHtml should be a boolean.
445+
-> Enables/Disables magic HTML routes (enabled by default).
446+
-> Read more at https://webpack.js.org/configuration/dev-server/#devservermagichtml"
447+
`;
448+
442449
exports[`options validate should throw an error on the "onAfterSetupMiddleware" option with 'false' value 1`] = `
443450
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
444451
- options.onAfterSetupMiddleware should be an instance of function.

test/cli/__snapshots__/basic.test.js.snap.webpack4

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ Options:
9999
--ipc [value] Listen to a unix socket.
100100
--live-reload Enables reload/refresh the page(s) when file changes are detected (enabled by default).
101101
--no-live-reload Disables reload/refresh the page(s) when file changes are detected (enabled by default)
102+
--magic-html Enables/Disables magic HTML routes (enabled by default).
103+
--no-magic-html Negative 'magic-html' option.
102104
--open [value...] Allows to configure dev server to open the browser(s) and page(s) after server had been started (set it to true to open your default browser).
103105
--no-open Does not open the default browser.
104106
--open-target <value...> Opens specified page in browser.

test/cli/__snapshots__/basic.test.js.snap.webpack5

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ Options:
9898
--ipc [value] Listen to a unix socket.
9999
--live-reload Enables reload/refresh the page(s) when file changes are detected (enabled by default).
100100
--no-live-reload Negative 'live-reload' option.
101+
--magic-html Enables/Disables magic HTML routes (enabled by default).
102+
--no-magic-html Negative 'magic-html' option.
101103
--open [value...] Allows to configure dev server to open the browser(s) and page(s) after server had been started (set it to true to open your default browser).
102104
--no-open Negative 'open' option.
103105
--open-target <value...> Opens specified page in browser.

test/cli/magicHtml-option.test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
"use strict";
2+
3+
const { testBin } = require("../helpers/test-bin");
4+
const port = require("../ports-map")["cli-magic-html"];
5+
6+
describe('"liveReload" CLI option', () => {
7+
it('should work using "--magic-html"', async () => {
8+
const { exitCode } = await testBin(["--port", port, "--magic-html"]);
9+
10+
expect(exitCode).toEqual(0);
11+
});
12+
13+
it('should work using "--no-magic-html"', async () => {
14+
const { exitCode } = await testBin(["--port", port, "--no-magic-html"]);
15+
16+
expect(exitCode).toEqual(0);
17+
});
18+
});
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`magicHtml option disabled should not handle GET request to magic async html: console messages 1`] = `
4+
Array [
5+
"Failed to load resource: the server responded with a status of 404 (Not Found)",
6+
]
7+
`;
8+
9+
exports[`magicHtml option disabled should not handle GET request to magic async html: response headers content-type 1`] = `"text/html; charset=utf-8"`;
10+
11+
exports[`magicHtml option disabled should not handle GET request to magic async html: response status 1`] = `404`;
12+
13+
exports[`magicHtml option disabled should not handle HEAD request to magic async html: console messages 1`] = `
14+
Array [
15+
"Failed to load resource: the server responded with a status of 404 (Not Found)",
16+
]
17+
`;
18+
19+
exports[`magicHtml option disabled should not handle HEAD request to magic async html: response headers content-type 1`] = `"text/html; charset=utf-8"`;
20+
21+
exports[`magicHtml option disabled should not handle HEAD request to magic async html: response status 1`] = `404`;
22+
23+
exports[`magicHtml option enabled should handle GET request to magic async html: console messages 1`] = `
24+
Array [
25+
"[HMR] Waiting for update signal from WDS...",
26+
"Hey.",
27+
"[webpack-dev-server] Hot Module Replacement enabled.",
28+
"[webpack-dev-server] Live Reloading enabled.",
29+
]
30+
`;
31+
32+
exports[`magicHtml option enabled should handle GET request to magic async html: response headers content-type 1`] = `"text/html; charset=utf-8"`;
33+
34+
exports[`magicHtml option enabled should handle GET request to magic async html: response status 1`] = `200`;
35+
36+
exports[`magicHtml option enabled should handle HEAD request to magic async html: console messages 1`] = `Array []`;
37+
38+
exports[`magicHtml option enabled should handle HEAD request to magic async html: response headers content-type 1`] = `"text/html; charset=utf-8"`;
39+
40+
exports[`magicHtml option enabled should handle HEAD request to magic async html: response status 1`] = `200`;

0 commit comments

Comments
 (0)