Convert Figma logo to code with AI

single-spa logosingle-spa

The router for easy microfrontends

13,283
916
13,283
43

Top Related Projects

15,789

📦 🚀 Blazing fast, simple and complete solution for micro frontends.

A simple, efficient and powerful micro front-end framework. 一款简约、高效、功能强大的微前端框架

Implementation examples of module federation , by the creators of module federation

12,939

Dynamic ES module loader

Quick Overview

Single-spa is a JavaScript framework for front-end microservices, allowing multiple JavaScript frameworks to coexist in a single page application. It enables developers to build scalable and maintainable applications by breaking them down into smaller, independently deployable pieces.

Pros

  • Allows multiple frameworks (React, Angular, Vue, etc.) to work together seamlessly
  • Enables gradual migration from legacy applications to modern frameworks
  • Improves application performance through lazy loading of microfrontends
  • Facilitates independent deployment and development of different parts of the application

Cons

  • Adds complexity to the application architecture
  • Requires careful planning and coordination between teams
  • May introduce performance overhead due to additional JavaScript loading
  • Learning curve for developers new to microfrontend architecture

Code Examples

  1. Registering a microfrontend:
import { registerApplication, start } from 'single-spa';

registerApplication({
  name: 'myApp',
  app: () => import('./my-app.js'),
  activeWhen: '/my-app'
});

start();
  1. Creating a root config:
import { registerApplication, start } from 'single-spa';

registerApplication({
  name: '@org/navbar',
  app: () => System.import('@org/navbar'),
  activeWhen: ['/']
});

registerApplication({
  name: '@org/app1',
  app: () => System.import('@org/app1'),
  activeWhen: ['/app1']
});

start();
  1. Lifecycle functions in a microfrontend:
export function bootstrap(props) {
  return Promise.resolve().then(() => {
    console.log('App bootstrapped');
  });
}

export function mount(props) {
  return Promise.resolve().then(() => {
    console.log('App mounted');
  });
}

export function unmount(props) {
  return Promise.resolve().then(() => {
    console.log('App unmounted');
  });
}

Getting Started

  1. Install single-spa:

    npm install single-spa
    
  2. Create a root config file (e.g., root-config.js):

    import { registerApplication, start } from 'single-spa';
    
    registerApplication({
      name: '@org/app1',
      app: () => System.import('@org/app1'),
      activeWhen: ['/app1']
    });
    
    start();
    
  3. Set up your HTML file:

    <script src="https://cdn.jsdelivr.net/npm/systemjs/dist/system.js"></script>
    <script src="root-config.js"></script>
    <div id="root"></div>
    
  4. Create and register your microfrontends following the single-spa lifecycle functions (bootstrap, mount, unmount).

Competitor Comparisons

15,789

📦 🚀 Blazing fast, simple and complete solution for micro frontends.

Pros of qiankun

  • Built-in support for JavaScript sandbox and CSS isolation
  • Simplified API and configuration compared to single-spa
  • Automatic assets prefetching for improved performance

Cons of qiankun

  • Less flexibility for custom implementations
  • Primarily designed for React applications, potentially limiting other frameworks
  • Steeper learning curve for developers new to micro-frontends

Code Comparison

single-spa:

import { registerApplication, start } from 'single-spa';

registerApplication({
  name: 'app1',
  app: () => import('./app1/main.js'),
  activeWhen: '/app1'
});

start();

qiankun:

import { registerMicroApps, start } from 'qiankun';

registerMicroApps([
  {
    name: 'app1',
    entry: '//localhost:8080',
    container: '#container',
    activeRule: '/app1'
  }
]);

start();

Both single-spa and qiankun are popular micro-frontend frameworks, but they have different approaches. single-spa offers more flexibility and framework-agnostic solutions, while qiankun provides additional features like built-in sandboxing and simplified configuration. The choice between them depends on specific project requirements, team expertise, and desired level of control over the micro-frontend architecture.

A simple, efficient and powerful micro front-end framework. 一款简约、高效、功能强大的微前端框架

Pros of micro-app

  • Simpler setup and configuration process
  • Built-in support for sandbox isolation and CSS scoping
  • Better performance for large-scale applications with many micro-frontends

Cons of micro-app

  • Less flexible than single-spa for complex routing scenarios
  • Smaller community and ecosystem compared to single-spa
  • Limited support for non-React frameworks

Code Comparison

micro-app:

<micro-app name="app1" url="http://localhost:3000/app1/" baseroute="/app1"></micro-app>

single-spa:

registerApplication({
  name: 'app1',
  app: () => System.import('app1'),
  activeWhen: '/app1'
});

micro-app focuses on a declarative HTML-based approach, while single-spa uses a more programmatic JavaScript configuration. micro-app's approach is simpler for basic use cases, but single-spa offers more flexibility for complex scenarios.

Both projects aim to solve micro-frontend architecture challenges, but they differ in their implementation and target use cases. micro-app is more opinionated and provides built-in features for isolation and performance, while single-spa offers greater flexibility and a larger ecosystem. The choice between them depends on specific project requirements and the desired level of control over the micro-frontend implementation.

Implementation examples of module federation , by the creators of module federation

Pros of module-federation-examples

  • Provides a wide range of examples for different use cases and frameworks
  • Demonstrates advanced Webpack 5 Module Federation capabilities
  • Offers more flexibility in terms of technology choices and integration options

Cons of module-federation-examples

  • Steeper learning curve due to the complexity of Module Federation concepts
  • Requires Webpack 5, which may not be suitable for all projects
  • Less opinionated approach, potentially leading to more decision-making for developers

Code Comparison

single-spa:

import { registerApplication, start } from 'single-spa';

registerApplication(
  'app1',
  () => import('./app1/app1.js'),
  (location) => location.pathname.startsWith('/app1')
);

start();

module-federation-examples:

const HtmlWebpackPlugin = require('html-webpack-plugin');
const ModuleFederationPlugin = require('webpack/lib/container/ModuleFederationPlugin');

module.exports = {
  plugins: [
    new ModuleFederationPlugin({
      name: 'app1',
      filename: 'remoteEntry.js',
      exposes: {
        './App': './src/App',
      },
      shared: ['react', 'react-dom'],
    }),
    new HtmlWebpackPlugin({
      template: './public/index.html',
    }),
  ],
};

Summary

While single-spa focuses on providing a simple and opinionated approach to microfrontends, module-federation-examples showcases the power and flexibility of Webpack 5's Module Federation. The choice between the two depends on project requirements, team expertise, and desired level of control over the microfrontend architecture.

12,939

Dynamic ES module loader

Pros of SystemJS

  • More flexible module loading system, supporting various module formats (CommonJS, AMD, UMD)
  • Better suited for general-purpose module loading in web applications
  • Provides a plugin system for custom loaders and transformations

Cons of SystemJS

  • Steeper learning curve compared to Single-spa
  • Less focused on micro-frontend architecture
  • May require more configuration for complex setups

Code Comparison

SystemJS:

System.import('./module.js').then(function(module) {
  module.doSomething();
});

Single-spa:

singleSpa.registerApplication(
  'appName',
  () => import('./app.js'),
  (location) => location.pathname.startsWith('/app')
);

Key Differences

  • SystemJS is a general-purpose module loader, while Single-spa focuses on micro-frontend architecture
  • Single-spa provides built-in lifecycle management for applications, whereas SystemJS requires additional setup for similar functionality
  • SystemJS offers more flexibility in module loading, but Single-spa simplifies micro-frontend implementation

Use Cases

  • Choose SystemJS for complex module loading requirements in various formats
  • Opt for Single-spa when building a micro-frontend architecture with multiple applications

Community and Ecosystem

  • Both projects have active communities and regular updates
  • Single-spa has a more specialized ecosystem for micro-frontend development
  • SystemJS has broader adoption for general module loading scenarios

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

npm version NPM Downloads

single-spa

Join the chat on Slack

Donate to this project

Official educational courses

Official single-spa hosting

A javascript framework for front-end microservices

Build micro frontends that coexist and can (but don't need to) be written with their own framework. This allows you to:

Sponsors

Franklin

To add your company's logo to this section:

Documentation

You can find the single-spa documentation on the website.

Check out the Getting Started page for a quick overview.

Demo and examples

Please see the examples page on the website.

Want to help?

Want to file a bug, contribute some code, or improve documentation? Excellent! Read up on our guidelines for contributing on the single-spa website.

Contributing

The main purpose of this repository is to continue to evolve single-spa, making it better and easier to use. Development of single-spa, and the single-spa ecosystem happens in the open on GitHub, and we are grateful to the community for contributing bugfixes and improvements. Read below to learn how you can take part in improving single-spa.

Code of Conduct

Single-spa has adopted a Code of Conduct that we expect project participants to adhere to. Please read the full text so that you can understand what actions will and will not be tolerated.

Contributing Guide

Read our contributing guide to learn about our development process, how to propose bugfixes and improvements, and how to build and test your changes to single-spa.

NPM DownloadsLast 30 Days