https://github.com/module-federation/rollup-federation
Module Federation within the rollup bundler
https://github.com/module-federation/rollup-federation
Last synced: about 1 year ago
JSON representation
Module Federation within the rollup bundler
- Host: GitHub
- URL: https://github.com/module-federation/rollup-federation
- Owner: module-federation
- License: mit
- Created: 2020-06-26T00:06:04.000Z (about 6 years ago)
- Default Branch: release
- Last Pushed: 2021-08-12T16:01:07.000Z (almost 5 years ago)
- Last Synced: 2025-04-13T03:23:54.622Z (about 1 year ago)
- Language: JavaScript
- Size: 244 KB
- Stars: 81
- Watchers: 3
- Forks: 4
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# rollup-federation
🍣 A Rollup plugin which enables consumption of
[Federated Modules](https://webpack.js.org/concepts/module-federation/).
This plugin essentially reproduces the functionality of Webpack's
[ContainerReferencePlugin](https://webpack.js.org/concepts/module-federation/#containerreferenceplugin-low-level)
and
[OverridablesPlugin](https://webpack.js.org/concepts/module-federation/#overridablesplugin-low-level).
## Limitations
This is **not** full support for Module Federation, there are limitations:
- Can not act as a container.
- This means you can not federate modules from Rollup to Webpack
- Both the Rollup and Webpack container builds need to have the same target
- Has only been tested with
[SystemJS](https://github.com/systemjs/systemjs)
- Should theoretically work with
[AMD](https://requirejs.org/docs/whyamd.html#amd) as well, give it a try
and provide feedback.
## Requirements
This plugin requires an [LTS](https://github.com/nodejs/Release) Node version
(v8.0.0+) and Rollup v1.20.0+.
## Install
Using npm:
```console
npm install @module-federation/rollup-federation --save-dev
```
## Usage
Create a `rollup.config.js`
[configuration file](https://www.rollupjs.org/guide/en/#configuration-files) and
import the plugin:
```js
import federation from '@module-federation/rollup-federation';
export default {
input: 'src/index.js',
output: {
dir: 'output',
format: 'system',
},
plugins: [
federation({
remotes: {
foo: 'remote_foo',
},
shared: {
lodash: '^4.17.0',
},
}),
],
};
```
Import your remote:
```js
(async () => {
const fooHello = await import('foo/hello');
fooHello.default('world');
})();
```
Then call `rollup` either via the
[CLI](https://www.rollupjs.org/guide/en/#command-line-reference) or the
[API](https://www.rollupjs.org/guide/en/#javascript-api).
## Options
### `remotes`
Type: `Object`
Default: `null`
An `Object` that specifies the remotes that will be consumed.
```
remotes: {
'import_name': 'import_alias'
}
```
### `shared`
Type: `Object`
Default: `null`
An `Object` that specifies the shared dependencies.
```
shared: {
lodash: '^4.17.0',
react: {
eager: true,
singleton: true,
requiredVersion: '16.13.1',
},
"react-dom": {
eager: true,
singleton: true,
requiredVersion: '16.13.1',
}
}
```