Skip to content

Commit

Permalink
new compiler hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
ScriptedAlchemy committed May 25, 2022
1 parent ce2d956 commit 86e59a4
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 11 deletions.
47 changes: 37 additions & 10 deletions lib/with-federated-sidecar.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ const buildClientRemotes = (federationPluginOptions, webpack) => {
}, {});
return clientRemotes;
};

const nextInternals = {
"next/dynamic": {
requiredVersion: false,
Expand Down Expand Up @@ -405,18 +406,31 @@ const withModuleFederation =
));

let loadableContent;
try {
if (
fs.existsSync(
path.join(
compilation.options.output.path,
"../../federated-loadable-manifest.json"
)
)
) {
loadableContent = require(path.join(
compilation.options.output.path,
"../federated-loadable-manifest.json"
"../../federated-loadable-manifest.json"
));
} catch (e) {
log(
} else if (
fs.existsSync(
path.join(
compilation.options.output.path,
"../federated-loadable-manifest.json"
)
);
)
) {
loadableContent = require(path.join(
compilation.options.output.path,
"../federated-loadable-manifest.json"
));
} else {
log(
"no federated loadable manifest found, it doesnt look like there are any local dynamic imports"
);
Expand Down Expand Up @@ -627,12 +641,25 @@ const withModuleFederation =

// in production or on server build use tapAsync to wait for the full compilation of the sidecar
if (isProd || compiler.options.mode === "production") {
compiler.hooks.afterCompile.tapAsync(
"NextFederation",
(compilation, done) => {
run(compilation, done);
compiler.hooks.run.tap("NextFederation", (compilation) => {
if (
compilation.name === "server" ||
compilation.name === "client"
) {
const sidecarCompile = new Promise((res) => {
run(compilation, (err) => res(err));
});

compiler.hooks.afterCompile.tapAsync(
"NextFederation",
(compilation, done) => {
sidecarCompile.then((res) => {
done(res);
});
}
);
}
);
});
} else {
compiler.hooks.afterCompile.tap(
"NextFederation",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"public": true,
"name": "@module-federation/nextjs-ssr",
"version": "0.1.0-rc.6",
"version": "0.1.0-rc.7",
"description": "Module Federation CSR & SSR Support for Next.js",
"main": "bundle.js",
"types": "index.d.ts",
Expand Down

0 comments on commit 86e59a4

Please sign in to comment.