-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add experimental support for module federation
- Loading branch information
Morten N.O. Henriksen
committed
May 15, 2021
1 parent
8976811
commit 8fdc63b
Showing
4 changed files
with
65 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
--- | ||
id: module-federation | ||
title: Module Federation | ||
--- | ||
|
||
**EXPERIMENTAL!** This is feature is subject to change as we evaluate and gather feedback | ||
|
||
Module federation enables an application to expose a module to be consumed by itself or other applications. | ||
|
||
To enable module federation in a create react app add either a *.modulefederationrc.json* or *.modulefederationrc.js* in the root folder - depending on how dynamic the config needs to be. | ||
|
||
The configuration is simply passed to the `ModuleFederationPlugin` [Read more about the configuration](https://webpack.js.org/concepts/module-federation/#modulefederationplugin-high-level) or [Find examples on module-federation](https://github.com/module-federation/module-federation-examples#module-federation-examples) | ||
|
||
Examples: | ||
|
||
App 1 | ||
```json | ||
// .modulefederationrc.json | ||
{ | ||
"name": "app1", | ||
"remotes": { | ||
"app2": "app2@http://localhost:3002/remoteEntry.js" | ||
}, | ||
"shared": ["react", "react-dom"] | ||
} | ||
``` | ||
|
||
App 2 | ||
```js | ||
// .modulefederationrc.js | ||
module.exports = { | ||
name: "app2", | ||
filename: "remoteEntry.js", | ||
exposes: { | ||
"./Button": "./src/Button" | ||
}, | ||
shared: ["react", "react-dom"], | ||
}; | ||
``` | ||
|
||
Note: | ||
Currently there is not a template for creating an app with federated modules, but rename eg. the `index.js` to `bootstrap.js` and add a new `index.js` with the following code: | ||
```js | ||
import("./bootstrap"); | ||
``` |
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
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