Skip to content

How to import components from main app dynamically with module federation #4029

Answered by yf-yang
yf-yang asked this question in Q&A

You must be logged in to vote

OK it works.

init({
  name: 'app1',
  remotes: [],
});

// ...

function App() {
  // ...
  const setApp2 = () => {
    init({
      name: 'app1',
      remotes: [
        {
          name: 'app2',
          entry: 'http://localhost:3002/remoteEntry.js',
        },
      ],
    });
    setSystem({
      scope: 'app2',
      module: 'Widget',
    });
  };

  const setApp3 = () => {
    init({
      name: 'app1',
      remotes: [
        {
          name: 'app3',
          entry: 'http://localhost:3003/remoteEntry.js',
        },
      ],
    });
    setSystem({
      scope: 'app3',
      module: 'Widget',
    });
  };

  // ...
}

Replies: 1 comment 2 replies

You must be logged in to vote
2 replies
@yf-yang

@yf-yang

Answer selected by yf-yang
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant