Enable Module Federation
Feature Description: I am requesting the integration of module federation into the Reflex framework. Module federation allows for dynamic code splitting, sharing, and loading between different parts of a web application, enhancing modularity and reducing code duplication. This feature would empower Reflex users to build more efficient and modular web applications.
Use Case: Use cases for module federation in Reflex include:
β’ Developing microfrontend architectures.
β’ Building large-scale web applications with shared components.
β’ Improving performance through on-demand loading of resources.
Implementation Ideas: The integration could involve configuring and leveraging either Webpack or Vite, both of which have established support for module federation. Reflex could provide a straightforward way to define and manage shared modules and dependencies.
Benefits:
β’ Enhanced modularity and code organization.
β’ Reduced duplication of code and resources.
β’ Improved application performance through optimized loading.
β’ Empowerment of Reflex developers to work on large-scale projects more efficiently.
Potential Challenges:
β’ Compatibility with existing Reflex features and configurations.
β’ Ensuring ease of use and clear documentation for Reflex users.
β’ Keeping up with updates and changes in Webpack or Vite configurations.
Community Impact: This feature would have a positive impact on the Reflex community by making the framework even more versatile and suitable for a broader range of web development projects. It would attract developers looking for efficient solutions for building complex web applications.
Additional Information: Module federation is a well-established practice in the web development community, and its integration into Reflex would align the framework with modern development needs and trends.
it appears to work without touching any code in reflex CLI.
After project creation cd to .web directory:
- added node package -> https://www.npmjs.com/package/@module-federation/nextjs-mf
- added the config ->
const NextFederationPlugin = require('@module-federation/nextjs-mf');
module.exports = {
basePath: "",
compress: true,
reactStrictMode: true,
trailingSlash: true,
webpack(config, options) {
const { isServer } = options;
config.plugins.push(
new NextFederationPlugin({
name: 'next2',
remotes: {
next1: next1@http://localhost:3001/_next/static/${isServer ? 'ssr' : 'chunks'}/remoteEntry.js,
},
filename: 'static/chunks/remoteEntry.js',
exposes: {
'./index': './pages/index.js',
},
shared: {
// whatever else
},
})
);
return config;
},
};
- curl or browser get request to http://localhost:3000/_next/static/chunks/remoteEntry.js
yields the module file -> load from static/chunks or static/ssr depending on the host environment to be clear.
i do however understand this is a very naive configuration example that does not cover all of the potential use cases. Nor does it serve the purpose of letting the Reflex CLI help manage this configuration but thought it helpful to post in here as a potential starting point.
This sounds interesting - I think it may be related to this old issue: https://github.com/reflex-dev/reflex/issues/46
I think it is a different request. It seems the other post is asking for a way to take an existing application and then also run reflex along side it from the same server. What I'd like to be able to do is write my own app or component as part of a reflex app and then have a configuration that allows others to consume that component from a separate application written in something else. (Or the same). A concept called micro front ends, and specifically using module federation to achieve this goal. My use case is the simpler version of this process, I just need to be able to expose a component to someone else. I think the complication may come in if you try to wrap someone else's component to use in reflex.