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 🙏

© 2026 – Pkg Stats / Ryan Hefner

front-components

v0.0.5

Published

Compose different microfrontend in a portal.

Readme

front-components - compose different frontend microservices

Compose different microfrontend in a portal.

You can either instantiate a service as uncontrolled: it has access to browser url, and a global event bus provided by this package. uncontrolled services

Or you can instantiate a service as controlled by another one: it has access to a scoped router, and a scoped event bus controlled service

Install

npm install --save front-components

Registering a service

Service A should register itself as soon as it can, and provide:

  • a unique identifier
  • a way to mount this service on DOM
  • a way to unmount this service
import { registerInstance } from "front-components";

function mount(domElement) {
  // ... For exemple: ReactDOM.render(..., domElement)
}

function unmount(domElement) {
  // ... For exemple: ReactDOM.unmountComponentAtNode(domElement);
}

registerInstance({
  serviceId: "service-A",
  mount,
  unmount,
});

Instantiating a service

Load your service from you portal or another service, using its unique identifier. If service is in a local file you can use require, if it's on remote file you can use <script> tag or even systemJs:

  • instantiate an uncontrolled service with: instantiateAt('service-A', domElement);
  • instantiate an controlled service with: instantiateAt('service-A', domElement, { isControlled: true });

Events

To emit and listen to events from a service or portal:

import { emit, on } from "front-components";

emit("my-event");
on("my-event", (data) => console.log(data));

Location

A service should not directly access window.location and other history related stuff. Instead, it should gain access to navigation history using a plugin. For example, for React-router, you can use history from our plugin:

import { getReactRouterHistory } from "front-components-history";

const history = getReactRouterHistory();
// uncontrolled service => history will be browser history
// controlled service => history will be memory history

Basic usage

Some exemple with React.

Portal instantiate uncontrolled service

An uncontrolled service emit and listen to events in global bus. Portal has access to global event bus.

// ... service-a/index.js
import { emit } from "front-components";
import { getReactRouterHistory } from "front-components-history";

function mount(domElement) {
  // This will be browser history as service is uncontrolled
  const history = getReactRouterHistory();

  ReactDOM.render(<App history={history} />, domElement);
  emit("hello", { foo: "bar" });
}

function unmount(domElement) {
  ReactDOM.unmountComponentAtNode(domElement);
}

registerInstance({
  serviceId: "service-A",
  mount,
  unmount,
});

// ... portal/index.js
import { instantiateAt, on } from "front-components";

// Listen to global events
on("mounted", (data) => {
  console.log(data); // Once service-a will be mounted, this will be logged
});

// Instantiate service A
const div = document.getElementById("root");
instantiateAt("service-A", div).then(() => {
  console.log("service A instantiated");

  document.location = "new-url"; // will redirect service A
});

Portal instantiate controlled service

An controlled service emit and listen to events in a scoped event bus. Portal has no direct access to this event bus. Portal can retrieve service event bus after service has been mounted.

// ... service-b/index.js
import { emit } from "front-components";

function mount(domElement) {
  // This will be a memory history as service is controlled
  const history = getReactRouterHistory();

  ReactDOM.render(<App history={history} />, domElement);
  emit("hello", { foo: "bar" });
}

function unmount(domElement) {
  ReactDOM.unmountComponentAtNode(domElement);
}

registerInstance({
  serviceId: "service-b",
  mount,
  unmount,
});

// ... portal/index.js
import { instantiateAt, on } from "front-components";

// Listen to global events
on("mounted", (data) => {
  console.log(data); // This will never print, as service b is controlled
});

// Instantiate service B
const div = document.getElementById("root");
instantiateAt("service-B", div).then((controls) => {
  controls.events.on("an-event-from-service-b", (data) => {
    console.log(data); // This will print next time service b emit an event
  });

  // will move service B to a specific location, independant of browser url
  controls.history.push("/service-b-specific-url");
});