-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support Webpack Module Federation #12284
base: main
Are you sure you want to change the base?
Conversation
Hi @raspy8766! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at [email protected]. Thanks! |
Hello Hewlett Packard! Greetings from Domino's. Just wanted to thank you for doing this. We've been using your fork to to build out our module federation patterns and it's been great. Hopefully this'll get merged soon. Edit: fixed typo |
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
This feature is extremely interesting – to support module federation without having to use craco or use a separate webpack config. Any idea when this would show up in a release? |
@raspy8766, Thanks for sharing this! One thing, I can't get this PR to work in the CRA development env for a Host app and a Remote app scenario without slight modification. In the remote app, when running in the CRA development env we can not set the This will cause any Remote app to use a relative path and they end up looking for their own modules inside the host that is trying to consume them. In sum, in the development env, Remote apps will have the wrong URL when you try to load their shared modules from a Host app.
I could be missing something, but how are you getting around this? |
@SlowBurner that's correct, we're using the |
Cool! I got things working via |
thanks for your work on this @raspy8766 , really looking forward to seeing this get merged |
Thank you @raspy8766 for your efforts to get Module Federation support in CRA. This would help many if it gets merged. |
hey, great job <3! any ideea when this is going to be merged? |
Is there an example on how to use this in a monorepo with a host and remotes? |
Great addition, would like to see it merged! |
@devi-prsd - there is a repo with many examples here that are essentially tiny monorepos: https://github.com/module-federation/module-federation-examples If you mean a remote being deployed somewhere remotely from the host app (i.e. as static files on Netlify, GitHub pages), there is a post I wrote that explains how the setup could work, but you have to look past the business logic: https://kaoto.io/docs/add-custom-view/ Namely, in this project "step extensions" = remotes, and the URL of the remote gets passed in dynamically to the UI (host) from the API through a "view definition catalog" (basically just a configuration file). Or if you'd really like a blog post for this topic, let me know. |
Wow, brilliant! Looking forward to seeing this merged! |
bump |
I'm not able to get it to work. What am I missing? yarn create react-app app1 --template=typescript && \
git clone https://github.com/HewlettPackard/create-react-app.git && \
yarn --cwd="./create-react-app" && \
yarn --cwd="./mfe-app" add file:../create-react-app/packages/react-scripts Rename index.tsx -> bootstrap.tsx import("./bootstrap.tsx") app1/src/setupModuleFederation.js const { dependencies } = require('../package.json');
module.exports = {
name: "app1",
library: { type: "var", name: "app1" },
filename: "remoteEntry.js",
exposes: {
'./hello': "./src/hello.tsx"
},
remotes: {},
shared: {
...dependencies,
react: {
singleton: true,
requiredVersion: dependencies.react,
},
"react-dom": {
singleton: true,
requiredVersion: dependencies["react-dom"],
},
}
} app2/src/setupModuleFederation.js const { dependencies } = require('../package.json');
module.exports = {
name: "app2",
library: { type: "var", name: "app2" },
filename: "remoteEntry.js",
exposes: {},
remotes: {
app1: "app1@http://localhost:3001/remoteEntry.js"
},
shared: {
...dependencies,
react: {
singleton: true,
requiredVersion: dependencies.react,
},
"react-dom": {
singleton: true,
requiredVersion: dependencies["react-dom"],
},
}
} app2/src/App.tsx import Hello from 'app1/hello';
export default function App() {
return <div><Hello /></div>
} |
up |
how long to merge? |
Up again |
up, why so hard to review the damn files?? |
@allocenx Agreed, also wondering what the hold-up is ... 🤔 |
Any updates on this ? |
Any update on this? |
I'm about to give up on react-scripts altogether and just use raw Webpack |
cool down mate! 😅 |
I'm just sick of waiting on Facebook to support such a great Webpack feature when this PR has been sitting open for over a year now. Great work on your package though, kudos! Personally, I prefer to stick to official packages, so I just made a boilerplate using raw Webpack 🙂 |
I'd rather try to add the feature I want onto the official package with a script, than writing everything from scratch. |
FB makes tons of money and they can't even review this simple thing? |
up |
All, CRA is dead. |
Hi Team |
probably affected by layoffs 🤷 |
Module Federation Support
Description
This PR aims to support the Webpack 5 module federation plugin natively in CRA. Micro-frontends are becoming a more prevalent form of UI development for the enterprise environment. We love what create-react-app provides, but in order to get it working at the moment, we rely on these forked changes. Hopefully this PR has what you're looking for, if not I'm happy to make additional accommodations and open to suggestions.
Proposed Changes
setupModuleFederation.js
file that manages the webpack Module Federation pluginsetupModuleFederation.js
file is present, use the Module Federation pluginpublic
folder are now optional.Testing
Setup
react-scripts
from forked repoNegative Test
mfe-app
repo, runyarn start
http://localhost:3000/webpack-dev-server
and note the files listed appear as normalPositive Test
src/setupModuleFederation.js
file with the following contents:mfe-app
repopublic/index.html
file (optional)yarn start
http://localhost:3000/webpack-dev-server
and notice theremoteEntry.js
fileScreenshots
Webpack served assets:
remoteEntry.js
file: