forked from module-federation/core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add runtime mergeing (module-federation#8)
- Loading branch information
1 parent
54627ca
commit 5024990
Showing
4 changed files
with
49 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
const withModuleFederation = require("./withModuleFederation"); | ||
const patchSharing = require("./patchSharing"); | ||
|
||
const MergeRuntime = require("./merge-runtime"); | ||
module.exports = { | ||
withModuleFederation, | ||
patchSharing, | ||
MergeRuntime, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
const shell = require("shelljs"); | ||
const path = require("path"); | ||
const fs = require("fs"); | ||
module.exports = class MergeRemoteChunksPlugin { | ||
// Define `apply` as its prototype method which is supplied with compiler as its argument | ||
apply(compiler) { | ||
// Specify the event hook to attach to | ||
compiler.hooks.afterEmit.tap("MergeRemoteChunksPlugin", (output) => { | ||
const emittedAssets = Array.from(output.emittedAssets); | ||
const files = ["static/chunks/webpack", "static/runtime/remoteEntry"] | ||
.filter((neededChunk) => | ||
emittedAssets.some((emmitedAsset) => | ||
emmitedAsset.includes(neededChunk) | ||
) | ||
) | ||
.map((neededChunk) => | ||
emittedAssets.find((emittedAsset) => | ||
emittedAsset.includes(neededChunk) | ||
) | ||
) | ||
.map((file) => path.join(output.compiler.context, ".next", file)); | ||
|
||
if (files.length > 1) { | ||
console.log(files) | ||
const runtime = fs.readFileSync(files[0], "utf-8"); | ||
const remoteContainer = fs.readFileSync(files[1], "utf-8"); | ||
const merged = [runtime,remoteContainer].join("\n"); | ||
const remotePath = path.join(output.compiler.context, ".next/static"); | ||
if (fs.existsSync(remotePath)) { | ||
fs.mkdir(remotePath, { recursive: true }, (err) => { | ||
if (err) throw err; | ||
}); | ||
} | ||
fs.writeFile( | ||
path.resolve( | ||
output.compiler.context, | ||
".next/static/remoteEntry.js" | ||
), | ||
merged, | ||
()=>{} | ||
); | ||
} | ||
}); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
{ | ||
"extends": [ | ||
"config:base" | ||
] | ||
"extends": ["config:base"] | ||
} |