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

@entur/micro-frontend

v0.4.0

Published

Generic and minimal micro-frontend framework

Downloads

69

Readme

CircleCI

Generic and minimal micro-frontend library

Usage

The library consists of two main parts:

MicroFrontend

A React component to be used by the hosting application to render a micro-frontend at a specific location in the component tree in a React application.

You can bring your own Payload type to specify a contract between the hosting application and the micro-frontend. The payload is an object that you can use to provide context, such as a function to get an authorization token.

<MicroFrontend<DefaultPayload>
    id="my-cool-micro-frontend"
    host="example.org"
    staticPath="/static"
    name="My Cool Micro Frontend"
    payload={{
        getToken: auth.getAccessToken
    }}
    FetchStatus={FetchStatus}
    handleError={e => console.log(e)}
/>
  • id: The id corresponding to the microFrontendId argument of registerMicroFrontend.
  • name: Human-readable name of micro-frontend
  • host: The fully qualified hostname of the micro-frontend.
  • staticPath: The path where static files are located on host.
  • payload: Payload that should be delivered to the micro-frontend upon mounting.
  • FetchStatus: A component that will be rendered over the micro-frontend, to display rendering status. This component takes name and state og micro-frontend as props.
  • handleError: A function that will be called if there is an error during loading of micro-frontend

registerMicroFrontend

A function to be called from a micro-frontend to register mount and unmount handlers, which will be called by the hosting application. The register function is in theory framework agnostic, but has been tested only with React.

The function takes a generic type that specifies the payload contract.

registerMicroFrontend<DefaultPayload>({
    microFrontendId: 'my-cool-micro-frontend',
    mount: (mountPoint, payload) => {
        ReactDOM.render(<App {...payload} />, mountPoint);
    },
    unmount: (mountPoint) => {
        ReactDOM.unmountComponentAtNode(mountPoint);
    },
});

Requirements

The MicroFrontend component assumes that there is an asset-manifest.json file located at the path given by the staticPath prop at the given host prop. The structure of this file is assumed to follow the standard output of react-scripts which uses webpack-manifest-plugin to generate the file.

When using TypeScript, use either the DefaultPayload type or provide your own, to describe the payload that is passed from the hosting application to the micro-frontend.

Deployment

Build:

npm run build

Update version:

npm version [patch, minor, major]

Publish

npm publish

Push to github

git push && git push --tags