npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@empjs/module-federation-enhanced

v0.6.10-stable

Published

This package provides enhanced features for module federation.

Downloads

79

Readme

@module-federation/enhanced

This package provides enhanced features for module federation.

The following items are exported:

  • ModuleFederationPlugin
  • ContainerPlugin
  • ContainerReferencePlugin
  • SharePlugin
  • ConsumeSharedPlugin
  • ProvideSharedPlugin
  • FederationRuntimePlugin
  • AsyncBoundaryPlugin
  • HoistContainerReferencesPlugin

Documentation

See https://module-federation.io/guide/basic/webpack.html for details.

ModuleFederationPlugin

Configuration

name

  • Type: string
  • Required: No

The name of the container.

exposes

  • Type: Exposes
  • Required: No
  • Default: undefined

Used to specify the modules and file entry points that are exposed via Module Federation. After configuration, the exposed modules will be extracted into a separate chunk, and if there are async chunks, they will also be extracted into a separate chunk (the specific splitting behavior depends on the chunk splitting rules).

The Exposes type is defined as follows:

type Exposes = (ExposesItem | ExposesObject)[] | ExposesObject;

type ExposesItem = string;

type ExposesItems = ExposesItem[];

interface ExposesObject {
  [exposeKey: string]: ExposesConfig | ExposesItem | ExposesItems;
}

Here, exposeKey is essentially the same as the Package Entry Points specification (except that regular expression matching is not supported).

For example:

module.exports = {
  plugins: [
    new ModuleFederationPlugin({
      name: 'mfButton',
      exposes: {
        // Note: "./" is not supported
        '.': './src/index.tsx',
        './add': './src/utils/add.ts',
        './Button': './src/components/Button.tsx',
      },
    }),
  ],
};

remotes

This is a consumer-specific parameter. If remotes is set, it can be considered as a consumer.

  • Type: Remotes
  • Required: No
  • Default: undefined

This is used to specify how Module Federation consumes remote modules.

The Remotes type is defined as follows:

type Remotes = (RemotesItem | RemotesObject)[] | RemotesObject;

type RemotesItem = string;
type RemotesItems = RemotesItem[];

interface RemotesObject {
  [remoteAlias: string]: RemotesConfig | RemotesItem | RemotesItems;
}

Here, remoteAlias is the name actually used by the user and can be configured arbitrarily. For example, if remoteAlias is set to demo, the consumption method is import xx from 'demo'.

shared

  • Type: Shared
  • Required: No
  • Default: undefined

shared is used to share common dependencies between consumers and producers, reducing runtime download size and thus improving performance.

The Shared type is defined as follows:

type Shared = (SharedItem | SharedObject)[] | SharedObject;

type SharedItem = string;

interface SharedObject {
  [k: string]: SharedConfig | SharedItem;
}

singleton

  • Type: boolean
  • Required: No
  • Default: false

Determines whether only one version of the shared module is allowed in the shared scope (singleton mode).

  • If the value is true, singleton mode is enabled; if the value is false, singleton mode is not enabled.
  • If singleton mode is enabled, the shared dependencies of the remote application components and host application are loaded only once, and a higher version is loaded when the versions are not consistent. At this time, a warning will be given to the lower version side:
  • If singleton mode is not enabled, if the versions of shared dependencies between the remote application and host application are not consistent, the remote application and host application load their own dependencies

requiredVersion

  • Type: string
  • Required: False
  • Default: require('project/package.json')[devDeps | dep]['depName']

The required version can be a version range. The default value is the dependency version of the current application.

  • When using shared dependencies, it will be judged whether the dependency version meets requiredVersion. If it does, it will be used normally. If it is less than requiredVersion, a warning will be issued in the console, and the smallest version in the current shared dependency will be used.
  • When one side sets requiredVersion and the other side sets singleton, the dependency of requiredVersion will be loaded, and the singleton side will directly use the dependency of requiredVersion, regardless of the version.

eager

:::warning When eager is set to true, the shared dependencies will be packaged into the entry file, which will cause the entry file to be too large. Please open with caution. eager: true is rarely recommended :::

  • Type: boolean
  • Required: False
  • Default: false

Determines whether to load shared modules immediately.

Under normal circumstances, you need to open the asynchronous entry, and then load shared asynchronously on demand. If you want to use shared but don't want to enable asynchronous entry, you can set eager to true .

runtimePlugins

  • Type: string[]
  • Required: False
  • Default: undefined

Used to add additional plug-ins required at runtime. The value is the path of the specific plug-in. It supports absolute/relative paths and package names.

Once set, the runtime plugin is automatically injected and used at build time.

implementation

  • Type: string
  • Required: False
  • Default: undefined

Used to modify the actual bundler runtime version. Path with value @module-federation/runtime-tools.