Skip to content

Conversation

2heal1
Copy link
Member

@2heal1 2heal1 commented Mar 8, 2024

Description

add registerRemotes api

registerRemotes

  • Type: registerRemotes(remotes: Remote[], options?: { force?: boolean }): void

  • Used to register remotes after init .

  • Type

function registerRemotes(remotes: Remote[], options?: { force?: boolean }) {}

type Remote = (RemoteWithEntry | RemoteWithVersion) & RemoteInfoCommon;

interface RemoteInfoCommon {
  alias?: string;
  shareScope?: string;
  type?: RemoteEntryType;
  entryGlobalName?: string;
}

interface RemoteWithEntry {
    name: string;
    entry: string;
}

interface RemoteWithVersion {
    name: string;
    version: string;
}
  • Details
    info: Please be careful when setting force:true !

If set force: true, it will merge remote(include loaded remote), and remove loaded remote cache , as well as console.warn to tell this action may have risks.

  • Example
import { init, registerRemotes } from '@module-federation/runtime';

init({
  name: '@demo/register-new-remotes',
  remotes: [
    {
      name: '@demo/sub1',
      entry: 'http://localhost:2001/mf-manifest.json',
    }
  ],
});

// add new remote @demo/sub2
registerRemotes([
  {
      name: '@demo/sub2',
      entry: 'http://localhost:2002/mf-manifest.json',
  }
]);

// override previous remote @demo/sub1
registerRemotes([
  {
      name: '@demo/sub1',
      entry: 'http://localhost:2003/mf-manifest.json',
  }
]);

Related Issue

#1942

Types of changes

  • Docs change / refactoring / dependency upgrade
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

Checklist

  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • I have updated the documentation.

@2heal1 2heal1 merged commit ce0597e into main Mar 15, 2024
@2heal1 2heal1 deleted the feat/register-remotes branch March 15, 2024 02:47
@2heal1 2heal1 mentioned this pull request Mar 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants