Paciolan / remote-component

Dynamically load a React Component from a URL
MIT License
591 stars 49 forks source link

Dependencies cache? #12

Closed popmanhe closed 3 years ago

popmanhe commented 3 years ago

I was wondering if dependencies are shared/cached between remote components? For instance, both Component A and Component B use Module C which is huge. So Component A and Component B both require Module C which does not exist in web application. My question is after Module C is loaded by Component A, will it be loaded again by Component B?

Thanks.

joelnet commented 3 years ago

The recommended way is to mark the dependencies as external. This is documented here https://github.com/Paciolan/remote-component#webpackconfigjs. The docs need improving and I'll provide some more details on dependency sharing in the near future.

Once the Remote Component has a dependency marked as external, it is not bundled inside the build. This dependency is then expected to be supplied by the Application.

The inside of the Application that consumes the Remote Component, you modify the remote-component.config.js to include those dependencies. Info here: https://github.com/Paciolan/remote-component#webpack

With both of these, the docs need to be greatly improved. This will be happening shortly.

What you describe is difficult to do because the components are siblings and do not have knowledge of each other. They would both be bundled with the dependency at build time. So even before the application runs them both, they would both already have those dependencies.

Cheers!