![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
single-spa
Advanced tools
single-spa is a JavaScript framework for front-end microservices. It allows you to build and manage multiple microfrontends that can coexist and interoperate within a single web application. This enables teams to work independently on different parts of a web application, using different frameworks if necessary.
Registering Applications
This feature allows you to register multiple applications with single-spa. Each application can be loaded dynamically and activated based on the URL path.
const singleSpa = require('single-spa');
singleSpa.registerApplication({
name: 'app1',
app: () => System.import('app1'),
activeWhen: ['/app1'],
customProps: {}
});
singleSpa.start();
Mounting and Unmounting Applications
This feature allows you to manually mount and unmount applications, giving you fine-grained control over which applications are active at any given time.
const singleSpa = require('single-spa');
singleSpa.registerApplication({
name: 'app2',
app: () => System.import('app2'),
activeWhen: ['/app2'],
customProps: {}
});
singleSpa.start();
// Manually mount an application
singleSpa.mountRootParcel('app2', { domElement: document.getElementById('app2-container') });
// Manually unmount an application
singleSpa.unmountRootParcel('app2');
Custom Events
This feature allows you to dispatch and listen for custom events, enabling communication between different microfrontends.
const singleSpa = require('single-spa');
singleSpa.registerApplication({
name: 'app3',
app: () => System.import('app3'),
activeWhen: ['/app3'],
customProps: {}
});
singleSpa.start();
// Dispatch a custom event
window.dispatchEvent(new CustomEvent('custom-event', { detail: { someData: 'data' } }));
// Listen for a custom event
window.addEventListener('custom-event', (event) => {
console.log(event.detail.someData);
});
qiankun is a micro-frontend framework based on single-spa. It provides additional features like sandboxing and lifecycle hooks, making it easier to manage microfrontends in complex applications.
mooa is a micro-frontend framework inspired by single-spa. It focuses on Angular applications and provides a simpler API for integrating multiple Angular microfrontends.
icestark is a micro-frontend framework developed by Alibaba. It offers a set of tools and conventions for building and managing microfrontends, with a focus on React and Vue applications.
Build micro frontends that coexist and can each be written with their own framework. This allows you to:
A live demo is available and the source code for that demo is available in the single-spa-examples repository.
Also, you can check out a simple webpack starter project which is simpler and hopefully easier to get started with.
Single-spa takes inspiration from React component lifecycles by applying lifecycles to entire applications. It started out of a desire to use React + react-router instead of being forever stuck with our AngularJS + ui-router application, but now single-spa supports almost any framework coexisting with any other. Since Javascript is notorious for the short-life of its many frameworks, we decided to make it easy to use whichever frameworks you want.
Apps built with single-spa are made up of the following pieces:
single-spa works with es5, es6+, typescript, webpack, systemjs, gulp, grunt, bower, ember-cli, or really anything build system you can think of. You can npm install it, jspm install it, or even just use a <script>
tag if you prefer. If you're not starting your application from scratch, you'll have to migrate your SPA to become a single-spa application.
single-spa works in Chrome, Firefox, Safari, IE11, and Edge.
Yep
See the docs. If you're looking for help with specific frameworks or build systems (React, Angular, Webpack, Ember, etc), check out the ecosystem wiki
Also, check out this step by step guide.
For a full example, check out this simple webpack example.
To create a single-spa application, you will need to do three things:
<html>
<body>
<script src="single-spa-config.js"></script>
</body>
</html>
// single-spa-config.js
import * as singleSpa from 'single-spa';
const appName = 'app1';
/* The loading function is a function that returns a promise that resolves with the javascript application module.
* The purpose of it is to facilitate lazy loading -- single-spa will not download the code for a application until it needs to.
* In this example, import() is supported in webpack and returns a Promise, but single-spa works with any loading function that returns a Promise.
*/
const loadingFunction = () => import('./app1/app1.js');
/* Single-spa does some top-level routing to determine which application is active for any url. You can implement this routing any way you'd like.
* One useful convention might be to prefix the url with the name of the app that is active, to keep your top-level routing simple.
*/
const activityFunction = location => location.pathname.startsWith('/app1');
singleSpa.registerApplication(appName, loadingFunction, activityFunction);
singleSpa.start();
//app1.js
let domEl;
export function bootstrap(props) {
return Promise
.resolve()
.then(() => {
domEl = document.createElement('div');
domEl.id = 'app1';
document.body.appendChild(domEl);
});
}
export function mount(props) {
return Promise
.resolve()
.then(() => {
// This is where you would normally use a framework to mount some ui to the dom. See https://github.com/CanopyTax/single-spa/blob/master/docs/single-spa-ecosystem.md.
domEl.textContent = 'App 1 is mounted!'
});
}
export function unmount(props) {
return Promise
.resolve()
.then(() => {
// This is normally where you would tell the framework to unmount the ui from the dom. See https://github.com/CanopyTax/single-spa/blob/master/docs/single-spa-ecosystem.md
domEl.textContent = '';
})
}
We're trying out github's Projects feature (here) and are keeping it up-to-date with the fancy things in the works for single-spa.
See single-spa api and application api.
Please submit a P.R. to this section if you start using single-spa.
FAQs
The router for easy microfrontends
The npm package single-spa receives a total of 104,095 weekly downloads. As such, single-spa popularity was classified as popular.
We found that single-spa demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.