Skip to content

Commit 22e4b5e

Browse files
committed
feat(Module Federation): Add a shared parameter for MF config factory.
The shared parameter allows to directly provide the shared object for the Webpack Module Federation Plugin. It extends generated shared definitions from the dependencies object and will overwrite existing entries.
1 parent 236d66e commit 22e4b5e

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

webpack/webpack.mf.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,16 @@ function shared_from_dependencies(...dependencies) {
3737
* @param {String} remote_entry - Path to which the new remote entry file is written to.
3838
* @param {String} filename - Name of the generated remote entry file. Default ``remote.min.js``.
3939
* @param {Object} dependencies - Object with dependency name - version specifier pairs. Is used to set up the shared dependencies including their version requirements.
40+
* @param {Object} shared - Directly provide the shared object for the Webpack Module Federation Plugin. Extends generated shared definitions from the dependencies object and will overwrite existing entries.
4041
* @returns {Object} - Webpack config partial with instantiated module federation plugins.
4142
*/
42-
function config({ name, remote_entry, filename = "remote.min.js", dependencies = {} }) {
43+
function config({
44+
name,
45+
remote_entry,
46+
filename = "remote.min.js",
47+
dependencies = {},
48+
shared = {},
49+
}) {
4350
// Create a JS-variable compatible name and add a prefix.
4451
const normalized_bundle_name =
4552
MF_NAME_PREFIX + name.match(/([_$A-Za-z0-9])/g).join("");
@@ -52,7 +59,10 @@ function config({ name, remote_entry, filename = "remote.min.js", dependencies =
5259
"./main": remote_entry,
5360
},
5461
}),
55-
shared: shared_from_dependencies(dependencies),
62+
shared: {
63+
...shared_from_dependencies(dependencies),
64+
...shared,
65+
},
5666
});
5767
}
5868

0 commit comments

Comments
 (0)