Skip to content

Commit 86e59a4

Browse files
new compiler hooks
1 parent ce2d956 commit 86e59a4

File tree

2 files changed

+38
-11
lines changed

2 files changed

+38
-11
lines changed

lib/with-federated-sidecar.js

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ const buildClientRemotes = (federationPluginOptions, webpack) => {
121121
}, {});
122122
return clientRemotes;
123123
};
124+
124125
const nextInternals = {
125126
"next/dynamic": {
126127
requiredVersion: false,
@@ -405,18 +406,31 @@ const withModuleFederation =
405406
));
406407

407408
let loadableContent;
408-
try {
409+
if (
410+
fs.existsSync(
411+
path.join(
412+
compilation.options.output.path,
413+
"../../federated-loadable-manifest.json"
414+
)
415+
)
416+
) {
409417
loadableContent = require(path.join(
410418
compilation.options.output.path,
411-
"../federated-loadable-manifest.json"
419+
"../../federated-loadable-manifest.json"
412420
));
413-
} catch (e) {
414-
log(
421+
} else if (
422+
fs.existsSync(
415423
path.join(
416424
compilation.options.output.path,
417425
"../federated-loadable-manifest.json"
418426
)
419-
);
427+
)
428+
) {
429+
loadableContent = require(path.join(
430+
compilation.options.output.path,
431+
"../federated-loadable-manifest.json"
432+
));
433+
} else {
420434
log(
421435
"no federated loadable manifest found, it doesnt look like there are any local dynamic imports"
422436
);
@@ -627,12 +641,25 @@ const withModuleFederation =
627641

628642
// in production or on server build use tapAsync to wait for the full compilation of the sidecar
629643
if (isProd || compiler.options.mode === "production") {
630-
compiler.hooks.afterCompile.tapAsync(
631-
"NextFederation",
632-
(compilation, done) => {
633-
run(compilation, done);
644+
compiler.hooks.run.tap("NextFederation", (compilation) => {
645+
if (
646+
compilation.name === "server" ||
647+
compilation.name === "client"
648+
) {
649+
const sidecarCompile = new Promise((res) => {
650+
run(compilation, (err) => res(err));
651+
});
652+
653+
compiler.hooks.afterCompile.tapAsync(
654+
"NextFederation",
655+
(compilation, done) => {
656+
sidecarCompile.then((res) => {
657+
done(res);
658+
});
659+
}
660+
);
634661
}
635-
);
662+
});
636663
} else {
637664
compiler.hooks.afterCompile.tap(
638665
"NextFederation",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"public": true,
33
"name": "@module-federation/nextjs-ssr",
4-
"version": "0.1.0-rc.6",
4+
"version": "0.1.0-rc.7",
55
"description": "Module Federation CSR & SSR Support for Next.js",
66
"main": "bundle.js",
77
"types": "index.d.ts",

0 commit comments

Comments
 (0)