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

dynamic-module-federation

v0.3.0

Published

Tool for importing module federated components/apps at runtime

Downloads

8

Readme

dynamic-module-federation

This package provides React compatible component as well as hook to load and render Module-federated micro-apps in dynamic way.

  • It will dynamically import the repote applications and will only import the part of the remote application that is required.
  • It automatically handles the scenario where multiple instances of remote app is consumed inside the host application.
  • It provides easy to use react component and hook to use the imported modules from remote app.

Configure the remote app with module federation and serve it. In the host application, use the module federation plugin inside webpack but to import the remote entries dynamically don't mention those as remotes.

// webpack.config.js of host

new ModuleFederationPlugin({
  name: "hostApp",
  shared: {
    react: { singleton: true, eager: true},
    "react-dom": { singleton: true, eager: true}
    // rest of the configuration goes here
  }
})

To import remote module as a react component:

import ModFedRemoteLoader from 'dynamic-module-federation'

<ModFedRemoteLoader
  remoteUrl={/* use the remote url of the application. Ex: http://localhost:3001/remoteEntry.js */}
  scope={/* The name of the remote application */}
  module={ /* The module from the remote app that you want to use Ex: "./Button" */}
  loadingComponent={/* Optional. To show a loading screen while the remote module is getting loaded */}
  remoteEntryLoadedCallback={/* Optional. If we want to run some functions after the remote Entry file is loaded. The logging utilities can be added here. */}
  errorLogCallback={/* Optional. If we want to run any function in case of error while loading the remote module. The logging utilities can be added here */}
  props={/* Optional. To add any optional parametrs in the component */ }
>

It also allows to load modules from remote app through a hook. Use the hook useFederatedComponent for this purpose.

import { useFederatedComponent } from 'dynamic-module-federation'

const RemoteComponent = () => {
  const {error, Component} = useFederatedComponent({
    remoteUrl: 'http://localhost:3002/remoteEntry.js',
    scope: 'remoteAppSecond',
    module: './Button'
  })
  if (error) {
    // errorLog(error)
  }
  return (
    <>
      {Component && (
        <Suspense fallback={<>Loading ... </>}>
          <Component />
        </Suspense>
      )}
    </>
  )
}

You can view a demonstration of utilizing this application at https://github.com/abc-utils/dynamic-module-federation-example .