What is Component Level Ownership (CLO)?
It's a pattern of software design that shifts as much responsibility to the component as possible. We have heard of dumb components before… well these are smart components
The idea behind them is they work standalone or near standalone. Inside of a monolithic app, you'll probably find a lot of logic colocated at the page level. Data, state, props, that are sent down to dumb components. In a smart component, the page would send hints about what the component should do. In theory, I should be able to mount any component on a CRA app, pass it some very basic props/hints, and it'll do the rest of the job.
To achieve Component Level Ownership, each application needs to configure its Webpack Module Federation plugin with two options: name
and exposes
. The name
option defines the unique identifier of the application, which will be used by other applications to reference it. The exposes
option defines a mapping of keys to local files that contain the components to be exposed. For example:
The core concept of "Component Level Ownership" is to provide modules that are self sufficent, intepdent when possible. The host can pass props that tell it what to do, but its best when the component constols its own data supply and contracts.
Expose the component through your plugin configuration. The method for doing this may differ depending on the tool you are using. For example, with rsbuild, you would configure the exposes
option. With rspack, you would use the exposes
property. And with webpack, you would use the exposes
option in the ModuleFederationPlugin
configuration.
The component should require a minimal api contract with the host since it is able to fetch it own data