Skip to content

Commit

Permalink
updated docs (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
ScriptedAlchemy authored Oct 25, 2020
1 parent 0121c3f commit 61241e9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,24 @@ class MyDocument extends Document {
const Nav = (await import("../components/nav")).default;
const _ = await import("lodash");
```

## Experimental

Use at your own risk.

Next.js uses `runtimeChunk:'single'`
Which forces us to also add the webpack script itself. Till this is fixed in webpack, heres a plugin that will merge the runtimes back together for MF

```js
const {MergeRuntime} = require("@module-federation/nexjs-mf");
// in your next config.
config.plugins.push(new MergeRuntime());
```

This allows the following to be done

```diff
- <script src="http://localhost:3000/_next/static/chunks/webpack.js" />
- <script src="http://localhost:3000/_next/static/runtime/remoteEntry.js" />
+ <script src="http://localhost:3000/_next/static/remoteEntryMerged.js" />
```
5 changes: 2 additions & 3 deletions merge-runtime.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const shell = require("shelljs");
const path = require("path");
const fs = require("fs");
module.exports = class MergeRemoteChunksPlugin {
Expand All @@ -23,7 +22,7 @@ module.exports = class MergeRemoteChunksPlugin {
if (files.length > 1) {
const runtime = fs.readFileSync(files[0], "utf-8");
const remoteContainer = fs.readFileSync(files[1], "utf-8");
const merged = [runtime,remoteContainer].join("\n");
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) => {
Expand All @@ -36,7 +35,7 @@ module.exports = class MergeRemoteChunksPlugin {
".next/static/remoteEntryMerged.js"
),
merged,
()=>{}
() => {}
);
}
});
Expand Down

0 comments on commit 61241e9

Please sign in to comment.