BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News Piral, a Modern React-Based Microfrontends Library

Piral, a Modern React-Based Microfrontends Library

This item in japanese

Lire ce contenu en français

Bookmarks

Piral is a JavaScript library for creating modular "microfrontends" application based on React.

Microfrontends extend the microservices concept to front-end applications and help developers tackle the ever-growing size and complexity of JavaScript applications by breaking down a single SPA (Single Page Application) into multiple self-contained applications.

A simple microfrontends setup involves a shell application that loads a set of self-contained modules based on the current route.

In Piral, the shell application is called a "Piral instance". The self-contained modules are called "Pilets," both of which can be generated through the Piral CLI.

The Piral instance manages three aspects of the application:

  1. The application layout (e.g., footer, header, etc...)
  2. Shared components that can be shared between the individual Pilets
  3. Manages how Pilets are loaded and defines where they could integrate the shared components

The Pilets are individual web applications that manage different aspects of the website. While the Piral CLI defaults to React, developers can build Pilets using other libraries such as Angular or Vue.js using the provided plugins.

To get started with Piral, first install the Piral CLI globally using:

npm I piral-cli -g

Once the Piral CLI is installed, a new Piral application can be generated by running:

piral new --target app-name

This will generate a simple shell application that includes the base layout. Before generating the Pilets, we first need to run piral build, which generates a dist folder that contains two packages - release and emulator.

The emulator package is used to generate the Pilets and will generally be published to a private NPM registry to ensure all modules use the latest layout.

To generate the Pilet, run:

pilet new emulator-name --target pilet-name

Where the emulator name can either be the npm package or the local path to the emulator instance. To start the newly created Pilet, run pilet debug, which will be served from http://localhost:1234/.

Piral relies on a feed service that hosts the Pilet instances. Developers can set their own feed service based on the supplied example or use the free feed service provided by Piral.

Once a feed is set up, the Piral instance needs to be configured to pull Pilets from the created feed. This can be done by modifying the 'feedUrl' found in the 'index.tsx' of the Piral application.

Piral is an open-source library that is available under the MIT license. Contributions are encouraged to participate in the Piral GitHub project and should follow the Contributor Covenant Code of Conduct.

Rate this Article

Adoption
Style

BT