Skip to content

Commit cb24f40

Browse files
snitin315alexander-akait
authored andcommitted
refactor!: remove the magicHtml option (#4850)
1 parent d70a421 commit cb24f40

20 files changed

+63
-571
lines changed

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,6 @@ Options:
138138
--ipc [value] Listen to a unix socket.
139139
--live-reload Enables reload/refresh the page(s) when file changes are detected (enabled by default).
140140
--no-live-reload Disables reload/refresh the page(s) when file changes are detected (enabled by default).
141-
--magic-html Tells dev-server whether to enable magic HTML routes (routes corresponding to your webpack output, for example '/main' for 'main.js').
142-
--no-magic-html Disables magic HTML routes (routes corresponding to your webpack output, for example '/main' for 'main.js').
143141
--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).
144142
--no-open Does not open the default browser.
145143
--open-target <value...> Opens specified page in browser.

examples/magic-html/README.md

Lines changed: 0 additions & 55 deletions
This file was deleted.

examples/magic-html/app.js

Lines changed: 0 additions & 11 deletions
This file was deleted.

examples/magic-html/webpack.config.js

Lines changed: 0 additions & 13 deletions
This file was deleted.

lib/Server.js

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,6 @@ const schema = require("./options.json");
185185
* @property {boolean} [liveReload]
186186
* @property {DevMiddlewareOptions<Request, Response>} [devMiddleware]
187187
* @property {boolean} [compress]
188-
* @property {boolean} [magicHtml]
189188
* @property {"auto" | "all" | string | string[]} [allowedHosts]
190189
* @property {boolean | ConnectHistoryApiFallbackOptions} [historyApiFallback]
191190
* @property {boolean | Record<string, never> | BonjourOptions} [bonjour]
@@ -1228,9 +1227,6 @@ class Server {
12281227
options.liveReload =
12291228
typeof options.liveReload !== "undefined" ? options.liveReload : true;
12301229

1231-
options.magicHtml =
1232-
typeof options.magicHtml !== "undefined" ? options.magicHtml : true;
1233-
12341230
// https://github.com/webpack/webpack-dev-server/issues/1990
12351231
const defaultOpenOptions = { wait: false };
12361232
/**
@@ -2255,13 +2251,6 @@ class Server {
22552251
});
22562252
}
22572253

2258-
if (this.options.magicHtml) {
2259-
middlewares.push({
2260-
name: "serve-magic-html",
2261-
middleware: this.serveMagicHtml.bind(this),
2262-
});
2263-
}
2264-
22652254
// Register this middleware always as the last one so that it's only used as a
22662255
// fallback when no other middleware responses.
22672256
middlewares.push({
@@ -2953,51 +2942,6 @@ class Server {
29532942
}
29542943
}
29552944

2956-
/**
2957-
* @private
2958-
* @param {Request} req
2959-
* @param {Response} res
2960-
* @param {NextFunction} next
2961-
* @returns {void}
2962-
*/
2963-
serveMagicHtml(req, res, next) {
2964-
if (req.method !== "GET" && req.method !== "HEAD") {
2965-
return next();
2966-
}
2967-
2968-
/** @type {import("webpack-dev-middleware").API<Request, Response>}*/
2969-
(this.middleware).waitUntilValid(() => {
2970-
const _path = req.path;
2971-
2972-
try {
2973-
const filename =
2974-
/** @type {import("webpack-dev-middleware").API<Request, Response>}*/
2975-
(this.middleware).getFilenameFromUrl(`${_path}.js`);
2976-
const isFile =
2977-
/** @type {Compiler["outputFileSystem"] & { statSync: import("fs").StatSyncFn }}*/
2978-
(
2979-
/** @type {import("webpack-dev-middleware").API<Request, Response>}*/
2980-
(this.middleware).context.outputFileSystem
2981-
)
2982-
.statSync(/** @type {import("fs").PathLike} */ (filename))
2983-
.isFile();
2984-
2985-
if (!isFile) {
2986-
return next();
2987-
}
2988-
2989-
// Serve a page that executes the javascript
2990-
// @ts-ignore
2991-
const queries = req._parsedUrl.search || "";
2992-
const responsePage = `<!DOCTYPE html><html><head><meta charset="utf-8"/></head><body><script type="text/javascript" charset="utf-8" src="${_path}.js${queries}"></script></body></html>`;
2993-
2994-
res.send(responsePage);
2995-
} catch (error) {
2996-
return next();
2997-
}
2998-
});
2999-
}
3000-
30012945
// Send stats to a socket or multiple sockets
30022946
/**
30032947
* @private

lib/options.json

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -367,14 +367,6 @@
367367
},
368368
"link": "https://webpack.js.org/configuration/dev-server/#devserverlivereload"
369369
},
370-
"MagicHTML": {
371-
"type": "boolean",
372-
"description": "Tells dev-server whether to enable magic HTML routes (routes corresponding to your webpack output, for example '/main' for 'main.js').",
373-
"cli": {
374-
"negatedDescription": "Disables magic HTML routes (routes corresponding to your webpack output, for example '/main' for 'main.js')."
375-
},
376-
"link": "https://webpack.js.org/configuration/dev-server/#devservermagichtml"
377-
},
378370
"OnListening": {
379371
"instanceof": "Function",
380372
"description": "Provides the ability to execute a custom function when dev server starts listening.",
@@ -990,9 +982,6 @@
990982
"liveReload": {
991983
"$ref": "#/definitions/LiveReload"
992984
},
993-
"magicHtml": {
994-
"$ref": "#/definitions/MagicHTML"
995-
},
996985
"onListening": {
997986
"$ref": "#/definitions/OnListening"
998987
},

0 commit comments

Comments
 (0)