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

monteur

v0.2.5

Published

This library helps constructing micro frontends

Downloads

73

Readme

Monteur

Is a library to construct simple micro frontends based on fragments. A fragment is a separately deployed web application (micro frontend) consisting of at least an index.html file. Monteur allows the host fragment to load these micro frontend into the existing application and to communicate with the fragment. While doing this monteur is 100% framework agnostic :)

How it works

The concept of monteur is very basic and consists of 3 steps. The host application loads the fragment resources from the specified url, which have to return a html page. Once the resources are loaded, the initialization handshake is performed, to tell the fragment which data it should use to render. Last but not least the host and the fragment application can communicate via an event bus in both directions.

Monteur provides two different ways of rendering fragments. The first and easiest method is the framed approach which renders the micro frontend inside an iframe which provides great isolation and no app has to care about colliding styles or javascript. The second method is to fetch the html tags from the micro frontend index.html and append it to the current DOM. For the second method I clearly can say great power comes with great responsibility as you have to care about colliding styles, javascript and the urls. For more information read the howto for this method (coming soon).

How to use

Host application

Example based on React

Install monteur

npm i monteur

Create wrapper component to render fragment

import React from 'react';
import {Host} from 'monteur';

export function SomeMicroFrontend(props) {
  const container = useRef(null);

  useEffect(() => {
    let fragmentHolder;
    Host.renderFragment(
      container.current, 
      'https://micro.frontend/url',
      defaultConfig => ({crazyOption: props.crazyOption, name: 'myName'}),
      true
    ).then(fragment => {
      fragmentHolder = fragment;
      fragment.addEventListener('some-value-changed', newValue => props.onSomeValueChanged(newValue));
    });

    return () => fragmentHolder.destroy();
  }, [container]);

  return (<div ref={container} />);
}

Use the fragment component

import React from 'react';
import {SomeMicroFrontend} from './SomeMicroFrontend.jsx';

export function App() {
  const [val, setVal] = useState(null);
  return (
    <div>
      <p>Value from micro frontend {val}</p>
      <SomeMicroFrontend 
        crazyOption="Fancy value"
        onSomeValueChanged={newValue => setVal(newValue)}
      />
    </div>
  );
}
Fragment application

Example based on React

Install monteur

npm i monteur

Initialize fragment and bootstrap application.

import React from 'react';
import ReactDOM from 'react-dom';
import {Fragment} from 'monteur';

function bootstrap(config) {
  ReactDOM.render(
    <App crazyOption={config.crazyOption} name={config.name} />,
    document.getElementById('root')
  );
}

if (Fragment.isFragment()) {
  const defaultConfig = {name: 'Unknown'};
  Fragment.initialize(defaultConfig, config => bootstrap(config));
} else {
  // Bootstrap with dummy data or for standalone case
  bootstrap({name: 'Thomas', crazyOption: 'Super fancy value'});
}

Development

Commands
  • yarn build: Creates umd and es6 module build
  • yarn build:main: Creates umd build
  • yarn build:module: Creates es6 module build
  • yarn watch: Creates es6 module build on every file change (used for development with yarn example)
  • yarn lint: Executed eslint on src folder
  • yarn lint:fix: Corrects fixable linter errors
  • yarn example: Serves example pages using library's module build in dist folder
Local setup

For local development there is the example folder which provides a host application, a framed and unframed fragment. Running yarn example will serve the applications on the ports:

  • 8090: host application
  • 8091: framed fragment
  • 8092: unframed fragment

The examples read from the /dist folder. In order to apply library changes either execute yarn build:module after each change or execute yarn watch to build the library on every change.

Deployment
  1. Commit your changes following the existing commit msg pattern
  2. Push your changes
  3. run yarn prepare-release
  4. Execute the command git push --follow-tags origin main && npm publish