Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 1 addition & 18 deletions host/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,13 @@ const ModuleFederationPlugin = require("webpack/lib/container/ModuleFederationPl
const path = require("path");

module.exports = {
future: { webpack5: true },
webpack: (config, options) => {
const { buildId, dev, isServer, defaultLoaders, webpack } = options;
const mfConf = {
remotes: {
remoteLib: isServer
? "remoteLib@http://localhost:3002/node/remoteEntry.js"
//This is a hack (I cannot run successfully MF in client-side with NextJS and React, maybe doing smth wrong)
: {
external: `external new Promise((r, j) => {
window['remoteLib'].init({
react: {
"${packageJsonDeps.react}": {
get: () => Promise.resolve().then(() => () => globalThis.React),
}
}
});
r({
get: (request) => window['remoteLib'].get(request),
init: (args) => {}
});
})`
}
// : "remoteLib@http://localhost:3001/remoteEntry.js",
: "remoteLib@http://localhost:3002/web/remoteEntry.js"
},
shared: {
react: {
Expand Down
2 changes: 1 addition & 1 deletion host/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"start": "next start"
},
"dependencies": {
"next": "10.2.3",
"next": "11.0.1",
"react": "17.0.2",
"react-dom": "17.0.2"
},
Expand Down
13 changes: 5 additions & 8 deletions host/pages/_app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@ import Head from "next/head";
import "../styles/globals.css";
import React from "react";

//This is a part of a hack I need (sorry for that). Take a look at next.config.js
globalThis.React = React;

const SmartButton = (await import ("remoteLib/SmartButton")).default;

function MyApp({ Component, pageProps }) {
return (
<>
<Head>
<script src="http://localhost:3002/web/remoteEntry.js" />
</Head>
<Component {...pageProps} />
</>
<div>
Copy link

@vandercloak vandercloak Feb 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this break the nextjs functionality? Might just be better to remove the head + still use http://localhost:3000/testing

Or just remove the _app.js altogether.

<SmartButton/>
</div>
);
}

Expand Down
7 changes: 3 additions & 4 deletions remoteLib/src/SmartButton.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import React from "react";
import { Button } from "@material-ui/core";

const SmartButton = () => {
return <Button>
return <div>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why change this to a div? Should this be just plain html button?

If we are removing the @material-ui dep should that be removed from the package.json?

Hey, I'm a smart button
</Button>
</div>
};

export default SmartButton;
export default SmartButton;