Dynamic load provider
Modern.js provides Data Loader to help For data management, Data Loader is only executed on the server side and will not be executed repeatedly on the client side.
This chapter will introduce how to use Data Loader to obtain producer information and load it dynamically.
Create provider
Create a new provider for dynamic load.
1. Create configuration file
Create a module-federation.config.ts file in the project root directory and write the following content:
2. Apply plugin
Apply @module-federation/modern-js in modern.config.ts:
3. Create need to be exposed component
Create the file src/components/Image.tsx with the following content:
And create the corresponding style file, the content is as follows:
Create loader
Create a .data file with the same name in the corresponding routing file. Taking the root directory src/routes/page.tsx as an example, create src/routes/page.data.ts:
Load dynamic provider
Consume loader data and dynamically load the corresponding producer: