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: multi compiler mode with multiple web targets #3840

Merged
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
2 changes: 1 addition & 1 deletion client-src/utils/reloadApp.js
Expand Up @@ -15,7 +15,7 @@ function reloadApp({ hot, liveReload }, status) {
? // eslint-disable-next-line camelcase
__webpack_hash__
: status.previousHash || "";
const isInitial = status.currentHash.indexOf(webpackHash) === 0;
const isInitial = status.currentHash.indexOf(webpackHash) >= 0;

if (isInitial) {
const isLegacyInitial =
Expand Down
30 changes: 11 additions & 19 deletions lib/Server.js
Expand Up @@ -1150,26 +1150,18 @@ class Server {
}

setupHooks() {
const addHooks = (compiler) => {
compiler.hooks.invalid.tap("webpack-dev-server", () => {
if (this.webSocketServer) {
this.sendMessage(this.webSocketServer.clients, "invalid");
}
});
compiler.hooks.done.tap("webpack-dev-server", (stats) => {
if (this.webSocketServer) {
this.sendStats(this.webSocketServer.clients, this.getStats(stats));
}

this.stats = stats;
});
};
this.compiler.hooks.invalid.tap("webpack-dev-server", () => {
if (this.webSocketServer) {
this.sendMessage(this.webSocketServer.clients, "invalid");
}
});
this.compiler.hooks.done.tap("webpack-dev-server", (stats) => {
if (this.webSocketServer) {
this.sendStats(this.webSocketServer.clients, this.getStats(stats));
}

if (this.compiler.compilers) {
this.compiler.compilers.forEach(addHooks);
} else {
addHooks(this.compiler);
}
this.stats = stats;
});
}

setupHostHeaderCheck() {
Expand Down
4 changes: 2 additions & 2 deletions test/client/utils/reloadApp.test.js
Expand Up @@ -86,7 +86,7 @@ describe("'reloadApp' function", () => {

reloadApp(
{ hot: false, hotReload: true, liveReload: true },
{ isUnloading: false, currentHash: "other-mock-hash" }
{ isUnloading: false, currentHash: "changed-mock" }
);

setTimeout(() => {
Expand All @@ -101,7 +101,7 @@ describe("'reloadApp' function", () => {
test("should run liveReload when protocol is http:", (done) => {
reloadApp(
{ hot: false, hotReload: true, liveReload: true },
{ isUnloading: false, currentHash: "other-mock-hash" }
{ isUnloading: false, currentHash: "changed-mock" }
);

setTimeout(() => {
Expand Down
94 changes: 92 additions & 2 deletions test/e2e/__snapshots__/multi-compiler.test.js.snap.webpack4
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Multi compiler should work with multiple compilers: console messages 1`] = `
exports[`multi compiler should work with one web target configuration: console messages 1`] = `
Array [
"[HMR] Waiting for update signal from WDS...",
"Hey.",
Expand All @@ -9,4 +9,94 @@ Array [
]
`;

exports[`Multi compiler should work with multiple compilers: page errors 1`] = `Array []`;
exports[`multi compiler should work with one web target configuration: page errors 1`] = `Array []`;

exports[`multi compiler should work with two web target configurations with hot and live reload: console messages 1`] = `
Array [
"[HMR] Waiting for update signal from WDS...",
"one",
"[webpack-dev-server] Hot Module Replacement enabled.",
"[webpack-dev-server] Live Reloading enabled.",
]
`;

exports[`multi compiler should work with two web target configurations with hot and live reload: console messages 2`] = `
Array [
"[HMR] Waiting for update signal from WDS...",
"two",
"[webpack-dev-server] Hot Module Replacement enabled.",
"[webpack-dev-server] Live Reloading enabled.",
]
`;

exports[`multi compiler should work with two web target configurations with hot and live reload: page errors 1`] = `Array []`;

exports[`multi compiler should work with two web target configurations with hot and live reload: page errors 2`] = `Array []`;

exports[`multi compiler should work with two web target configurations with only hot reload: console messages 1`] = `
Array [
"[HMR] Waiting for update signal from WDS...",
"one",
"[webpack-dev-server] Hot Module Replacement enabled.",
]
`;

exports[`multi compiler should work with two web target configurations with only hot reload: console messages 2`] = `
Array [
"[HMR] Waiting for update signal from WDS...",
"two",
"[webpack-dev-server] Hot Module Replacement enabled.",
]
`;

exports[`multi compiler should work with two web target configurations with only hot reload: page errors 1`] = `Array []`;

exports[`multi compiler should work with two web target configurations with only hot reload: page errors 2`] = `Array []`;

exports[`multi compiler should work with two web target configurations with only live reload: console messages 1`] = `
Array [
"one",
"[webpack-dev-server] Live Reloading enabled.",
]
`;

exports[`multi compiler should work with two web target configurations with only live reload: console messages 2`] = `
Array [
"two",
"[webpack-dev-server] Live Reloading enabled.",
]
`;

exports[`multi compiler should work with two web target configurations with only live reload: page errors 1`] = `Array []`;

exports[`multi compiler should work with two web target configurations with only live reload: page errors 2`] = `Array []`;

exports[`multi compiler should work with universal configurations with hot and live reload: console messages 1`] = `
Array [
"[HMR] Waiting for update signal from WDS...",
"Hello from the browser",
"[webpack-dev-server] Hot Module Replacement enabled.",
"[webpack-dev-server] Live Reloading enabled.",
]
`;

exports[`multi compiler should work with universal configurations with hot and live reload: page errors 1`] = `Array []`;

exports[`multi compiler should work with universal configurations with only hot reload: console messages 1`] = `
Array [
"[HMR] Waiting for update signal from WDS...",
"Hello from the browser",
"[webpack-dev-server] Hot Module Replacement enabled.",
]
`;

exports[`multi compiler should work with universal configurations with only hot reload: page errors 1`] = `Array []`;

exports[`multi compiler should work with universal configurations with only live reload: console messages 1`] = `
Array [
"Hello from the browser",
"[webpack-dev-server] Live Reloading enabled.",
]
`;

exports[`multi compiler should work with universal configurations with only live reload: page errors 1`] = `Array []`;
94 changes: 92 additions & 2 deletions test/e2e/__snapshots__/multi-compiler.test.js.snap.webpack5
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Multi compiler should work with multiple compilers: console messages 1`] = `
exports[`multi compiler should work with one web target configuration: console messages 1`] = `
Array [
"[HMR] Waiting for update signal from WDS...",
"Hey.",
Expand All @@ -9,4 +9,94 @@ Array [
]
`;

exports[`Multi compiler should work with multiple compilers: page errors 1`] = `Array []`;
exports[`multi compiler should work with one web target configuration: page errors 1`] = `Array []`;

exports[`multi compiler should work with two web target configurations with hot and live reload: console messages 1`] = `
Array [
"[HMR] Waiting for update signal from WDS...",
"one",
"[webpack-dev-server] Hot Module Replacement enabled.",
"[webpack-dev-server] Live Reloading enabled.",
]
`;

exports[`multi compiler should work with two web target configurations with hot and live reload: console messages 2`] = `
Array [
"[HMR] Waiting for update signal from WDS...",
"two",
"[webpack-dev-server] Hot Module Replacement enabled.",
"[webpack-dev-server] Live Reloading enabled.",
]
`;

exports[`multi compiler should work with two web target configurations with hot and live reload: page errors 1`] = `Array []`;

exports[`multi compiler should work with two web target configurations with hot and live reload: page errors 2`] = `Array []`;

exports[`multi compiler should work with two web target configurations with only hot reload: console messages 1`] = `
Array [
"[HMR] Waiting for update signal from WDS...",
"one",
"[webpack-dev-server] Hot Module Replacement enabled.",
]
`;

exports[`multi compiler should work with two web target configurations with only hot reload: console messages 2`] = `
Array [
"[HMR] Waiting for update signal from WDS...",
"two",
"[webpack-dev-server] Hot Module Replacement enabled.",
]
`;

exports[`multi compiler should work with two web target configurations with only hot reload: page errors 1`] = `Array []`;

exports[`multi compiler should work with two web target configurations with only hot reload: page errors 2`] = `Array []`;

exports[`multi compiler should work with two web target configurations with only live reload: console messages 1`] = `
Array [
"one",
"[webpack-dev-server] Live Reloading enabled.",
]
`;

exports[`multi compiler should work with two web target configurations with only live reload: console messages 2`] = `
Array [
"two",
"[webpack-dev-server] Live Reloading enabled.",
]
`;

exports[`multi compiler should work with two web target configurations with only live reload: page errors 1`] = `Array []`;

exports[`multi compiler should work with two web target configurations with only live reload: page errors 2`] = `Array []`;

exports[`multi compiler should work with universal configurations with hot and live reload: console messages 1`] = `
Array [
"[HMR] Waiting for update signal from WDS...",
"Hello from the browser",
"[webpack-dev-server] Hot Module Replacement enabled.",
"[webpack-dev-server] Live Reloading enabled.",
]
`;

exports[`multi compiler should work with universal configurations with hot and live reload: page errors 1`] = `Array []`;

exports[`multi compiler should work with universal configurations with only hot reload: console messages 1`] = `
Array [
"[HMR] Waiting for update signal from WDS...",
"Hello from the browser",
"[webpack-dev-server] Hot Module Replacement enabled.",
]
`;

exports[`multi compiler should work with universal configurations with only hot reload: page errors 1`] = `Array []`;

exports[`multi compiler should work with universal configurations with only live reload: console messages 1`] = `
Array [
"Hello from the browser",
"[webpack-dev-server] Live Reloading enabled.",
]
`;

exports[`multi compiler should work with universal configurations with only live reload: page errors 1`] = `Array []`;
@@ -1,9 +1,9 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Universal compiler client bundle should have the inlined the client runtime: console messages 1`] = `Array []`;
exports[`universal compiler client bundle should have the inlined the client runtime: console messages 1`] = `Array []`;

exports[`Universal compiler client bundle should have the inlined the client runtime: page errors 1`] = `Array []`;
exports[`universal compiler client bundle should have the inlined the client runtime: page errors 1`] = `Array []`;

exports[`Universal compiler server bundle should NOT have the inlined the client runtime: console messages 1`] = `Array []`;
exports[`universal compiler server bundle should NOT have the inlined the client runtime: console messages 1`] = `Array []`;

exports[`Universal compiler server bundle should NOT have the inlined the client runtime: page errors 1`] = `Array []`;
exports[`universal compiler server bundle should NOT have the inlined the client runtime: page errors 1`] = `Array []`;
@@ -1,9 +1,9 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Universal compiler client bundle should have the inlined the client runtime: console messages 1`] = `Array []`;
exports[`universal compiler client bundle should have the inlined the client runtime: console messages 1`] = `Array []`;

exports[`Universal compiler client bundle should have the inlined the client runtime: page errors 1`] = `Array []`;
exports[`universal compiler client bundle should have the inlined the client runtime: page errors 1`] = `Array []`;

exports[`Universal compiler server bundle should NOT have the inlined the client runtime: console messages 1`] = `Array []`;
exports[`universal compiler server bundle should NOT have the inlined the client runtime: console messages 1`] = `Array []`;

exports[`Universal compiler server bundle should NOT have the inlined the client runtime: page errors 1`] = `Array []`;
exports[`universal compiler server bundle should NOT have the inlined the client runtime: page errors 1`] = `Array []`;
2 changes: 1 addition & 1 deletion test/e2e/module-federation.test.js
Expand Up @@ -8,7 +8,7 @@ const objectEntryConfig = require("../fixtures/module-federation-config/webpack.
const multiConfig = require("../fixtures/module-federation-config/webpack.multi.config");
const runBrowser = require("../helpers/run-browser");
const isWebpack5 = require("../helpers/isWebpack5");
const port = require("../ports-map")["universal-compiler"];
const port = require("../ports-map")["module-federation"];

const describeOnlyWebpack5 = isWebpack5 ? describe : describe.skip;

Expand Down