Vue CLI Plugin for single-spa

4.0.0 · active · verified Sun Apr 19

vue-cli-plugin-single-spa is an official plugin for Vue CLI that streamlines the process of integrating Vue applications into a single-spa microfrontend architecture. It automatically handles the necessary Webpack configuration and scaffolding to transform a standard Vue project into a single-spa microfrontend or parcel. The current stable version is 4.0.0, which notably shifted the default Webpack output module format to native ES modules. The project maintains a moderate release cadence, with consistent updates addressing Webpack compatibility, security, and feature enhancements. Its primary differentiator is its deep integration with the Vue CLI ecosystem, offering a simplified developer experience for creating single-spa compatible Vue applications without extensive manual Webpack configuration.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to add the `single-spa` plugin to a Vue CLI project and shows the typical structure of the generated `main.ts` file, setting up the Vue application as a single-spa microfrontend.

{
  // Step 1: Create a new Vue project (if you don't have one)
  // vue create my-single-spa-app
  // cd my-single-spa-app

  // Step 2: Add the single-spa plugin
  // Run this command in your project's root directory:
  // vue add single-spa@latest

  // The plugin will modify your main.ts (or main.js) to look similar to this:
  // main.ts (or main.js)
  import { h, createApp } from 'vue';
  import singleSpaVue from 'single-spa-vue';
  import App from './App.vue';
  // import router from './router'; // Uncomment if you have vue-router installed
  // import store from './store'; // Uncomment if you have Vuex installed

  const vueLifecycles = singleSpaVue({
    createApp,
    appOptions: {
      render() {
        return h(App, {
          props: {
            // single-spa props are passed as "custom props" to the root component
            name: this.name,
            mountParcel: this.mountParcel,
            singleSpa: this.singleSpa
          }
        });
      },
      // Uncomment the following if you use Vuex or Vue Router
      // el: '#app', // Not typically needed for single-spa apps unless rendering standalone
    },
    handleInstance(app) {
      // app.use(router); // Apply vue-router
      // app.use(store);  // Apply Vuex store
    },
  });

  export const bootstrap = vueLifecycles.bootstrap;
  export const mount = vueLifecycles.mount;
  export const unmount = vueLifecycles.unmount;
}

view raw JSON →