web-infra-dev / rspack

The fast Rust-based web bundler with webpack-compatible API 🦀️
https://rspack.dev
MIT License
9.11k stars 521 forks source link

[Feature]: Module.addBlock API #7174

Open jacob-ebey opened 1 month ago

jacob-ebey commented 1 month ago

What problem does this feature solve?

I'd like to add an async dependency to a module to enable async loading of known federated containers from a module that doesn't directly import them.

mod.addBlock(new AsyncDependenciesBlock(...));

What does the proposed API of configuration look like?

The existing Webpack Module.addBlock(...) API and Webpack new AsyncDependenciesBlock() behavior.

jacob-ebey commented 1 month ago

Aliasing the container chunk and module of the federation plugin's "remote container" under the global name of the container would also suffice for my use-case and is ultimately what I'm after.

__webpack_require__.e("container_global_name")

along with:

__webpack_require__("container_global_name")

If __webpack_require__("container_global_name") returned the { get, init } interface for the container I could move on with my life and never have a "federated" issue again. Make that go through the v1.5 plugin interface and architectures get very fun.