[RFC] Provide first-class support for Module Federation #1461
Replies: 4 comments 9 replies
-
why not a moduleFederation rsbuild plugin? |
Beta Was this translation helpful? Give feedback.
-
Congratulations on the work! 🎉 It would also be interesting to explore something with single-spa since many projects also work with it in webpack for microfrontend creation. Perhaps just applying examples of usage with module-federation and another with single-spa, thus covering the main microfrontend libraries. |
Beta Was this translation helpful? Give feedback.
-
@ScriptedAlchemy How do you feel about the naming of config, do you prefer |
Beta Was this translation helpful? Give feedback.
-
Because mf is a builtin plugin, so we can change the splitChunk value as function patchChunkSplit(compiler: Compiler, name: string): void {
const { splitChunks } = compiler.options.optimization;
const patchChunkSplit = (cacheGroup: CacheGroup) => {
switch (typeof cacheGroup) {
case 'boolean':
case 'string':
case 'function':
break;
// cacheGroup.chunks will inherit splitChunks.chunks, so you only need to modify the chunks that are set separately.
case 'object': {
if (cacheGroup instanceof RegExp) {
break;
}
if (!cacheGroup.chunks) {
break;
}
if (typeof cacheGroup.chunks === 'function') {
const prevChunks = cacheGroup.chunks;
cacheGroup.chunks = chunk => {
if (chunk.name && chunk.name === name) {
return false;
}
return prevChunks(chunk);
};
break;
}
if (cacheGroup.chunks === 'all') {
cacheGroup.chunks = chunk => {
if (chunk.name && chunk.name === name) {
return false;
}
return true;
};
break;
}
if (cacheGroup.chunks === 'initial') {
cacheGroup.chunks = chunk => {
if (chunk.name && chunk.name === name) {
return false;
}
return chunk.isOnlyInitial();
};
break;
}
}
default:
break;
}
};
if (!splitChunks) {
return;
}
// patch splitChunk.chunks
patchChunkSplit(splitChunks);
if (!splitChunks.cacheGroups) {
return;
}
// patch splitChunk.cacheGroups[key].chunks
Object.keys(splitChunks.cacheGroups).forEach(cacheGroupKey => {
patchChunkSplit(splitChunks.cacheGroups[cacheGroupKey]);
});
} According above code , it will force remoteEntry not be affected by user's chunkSplit strategy , and the strategy will work as expected in other files . |
Beta Was this translation helpful? Give feedback.
-
This RFC is intended to provide first-class support for Module Federation in Rsbuild.
Configuring MF
Rsbuild will provide a top-level
moduleFederation
option, which will make configuring MF in Rsbuild much easier.The above example is equivalent to the following config:
Details:
chunks: 'async'
: the default chunks in Rsbuild is'all'
, but split patch not working for MF, so we will need it toasync
to avoid the issue.assetPrefix: 'auto'
: the default assetPrefix (publicPath) in Rsbuild is'/'
, we need to set the default toauto
to make MF work.MF Version
Rsbuild uses MF v1.5 by default. If there is a need for other versions in the future, we can provide the
moduleFederation.version
option.Server-side Federation
The
moduleFederation
option currently only takes effect for client bundles (target === 'web'
).When Server-side federation is ready to use, we may also provide some form of support in Rsbuild.
For Modern.js
Modern.js is based on Rsbuild, so Modern.js projects can also use the new
moduleFederation
option.And Modern.js will enable source.enableAsyncEntry by default when using the
moduleFederation
option, this allows Modern.js to automatically create asynchronous boundaries for entry points.Related Issues
Beta Was this translation helpful? Give feedback.
All reactions