Top Related Projects
📦 🚀 Blazing fast, simple and complete solution for micro frontends.
Implementation examples of module federation , by the creators of module federation
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
- Registering a microfrontend:
import { registerApplication, start } from 'single-spa';
registerApplication({
name: 'myApp',
app: () => import('./my-app.js'),
activeWhen: '/my-app'
});
start();
- 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();
- 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
-
Install single-spa:
npm install single-spa
-
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();
-
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>
-
Create and register your microfrontends following the single-spa lifecycle functions (bootstrap, mount, unmount).
Competitor Comparisons
📦 🚀 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.
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.
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
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
single-spa
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:
- Use multiple frameworks on the same page without refreshing the page (React, AngularJS, Angular, Ember, or whatever you're using)
- Write new code, possibly with a new framework, without rewriting your existing app
- Lazy load code for improved initial load time.
Sponsors
To add your company's logo to this section:
- Become a recurring Open Collective sponsor of at least $100 a month.
- Become a recurring Github sponsor of at least $100 a month.
- Sponsor a core team member to implement a specific feature for single-spa. Pay our regular consulting rate. Inquire in our Slack workspace.
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.
Top Related Projects
📦 🚀 Blazing fast, simple and complete solution for micro frontends.
Implementation examples of module federation , by the creators of module federation
Dynamic ES module loader
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot