` that is appended to `document.body`.
diff --git a/versioned_docs/version-5.x/ecosystem-inferno.md b/versioned_docs/version-5.x/ecosystem-inferno.md
index bfc26d1f9..02884ccee 100644
--- a/versioned_docs/version-5.x/ecosystem-inferno.md
+++ b/versioned_docs/version-5.x/ecosystem-inferno.md
@@ -11,15 +11,15 @@ single-spa-inferno is a helper library that helps implement [single-spa register
First, in the application, run `npm install --save single-spa-inferno`. Then, add the following to your application's entry file.
```js
-import Inferno from 'inferno';
-import rootComponent from './path-to-root-component.js';
-import singleSpaInferno from 'single-spa-inferno';
+import Inferno from "inferno";
+import rootComponent from "./path-to-root-component.js";
+import singleSpaInferno from "single-spa-inferno";
const infernoLifecycles = singleSpaInferno({
Inferno,
createElement,
rootComponent,
- domElementGetter: () => document.getElementById('main-content'),
+ domElementGetter: () => document.getElementById("main-content"),
});
export const bootstrap = infernoLifecyles.bootstrap;
@@ -34,4 +34,4 @@ All options are passed to single-spa-inferno via the `opts` parameter when calli
- `inferno`: (required) The main Inferno object, which is generally either exposed onto the window or is available via `require('inferno')` or `import Inferno from 'inferno'`.
- `createElement`: (required) The default export from Inferno's `inferno-create-element` package.
- `rootComponent`: (required) The top level Inferno component which will be rendered.
-- `domElementGetter`: (required) A function that takes in no arguments and returns a DOMElement. This dom element is where the Inferno application will be bootstrapped, mounted, and unmounted.
\ No newline at end of file
+- `domElementGetter`: (required) A function that takes in no arguments and returns a DOMElement. This dom element is where the Inferno application will be bootstrapped, mounted, and unmounted.
diff --git a/versioned_docs/version-5.x/ecosystem-leaked-globals.md b/versioned_docs/version-5.x/ecosystem-leaked-globals.md
index d4f7a83ea..5370b2f75 100644
--- a/versioned_docs/version-5.x/ecosystem-leaked-globals.md
+++ b/versioned_docs/version-5.x/ecosystem-leaked-globals.md
@@ -9,33 +9,38 @@ that depend on global variables. Such applications are usually applications that
that were popular when ES modules were not yet available.
## What single-spa-leaked-globals does
+
single-spa-leaked-globals will remove specific global variables from `window` during your application's
[unmount lifecycle](/docs/building-applications#unmount), and add them back to `window` during your application's
[mount lifecycle](/docs/building-applications#mount).
## Before using single-spa-leaked-globals
+
It might be okay for single-spa applications to leak some global variables. Those leaked global variables could be harmless. Below are some
situations where using single-spa-leaked-globals could be useful. If your situation is not listed, consider not using single-spa-leaked-globals.
1. Your applications are accidentally sharing global variables and the order in which they are mounted matters. For example, the jQuery `$` variable
- is available at the start, but app1 installs a jQuery plugin that app2 assumes is there. If app2 is mounted
- before app1, you might get an error because the jQuery plugin is not installed. In that situation, the best solution is maybe to install
- the jQuery plugin inside of your [single-spa config](/docs/configuration). But if that's not desireable, you can use single-spa-leaked-globals
- to manage two separate versions of jQuery -- one for app1 and one for app2.
+ is available at the start, but app1 installs a jQuery plugin that app2 assumes is there. If app2 is mounted
+ before app1, you might get an error because the jQuery plugin is not installed. In that situation, the best solution is maybe to install
+ the jQuery plugin inside of your [single-spa config](/docs/configuration). But if that's not desireable, you can use single-spa-leaked-globals
+ to manage two separate versions of jQuery -- one for app1 and one for app2.
2. Your applications require different versions of the same global variable. For example, consider when app1 depends on
- an [underscorejs](https://underscorejs.org/) `_` global variable and app2 depends on a [lodash](https://lodash.com/) `_` global variable.
- They both need a global `_` variable, but expect different functions to be available on it. The same could be true for different versions of the
- same library, such as lodash 3 vs lodash 4. In those situations, you can use single-spa-leaked-globals to make sure the `_` that is available
- for app1 and app2 is the correct one.
+ an [underscorejs](https://underscorejs.org/) `_` global variable and app2 depends on a [lodash](https://lodash.com/) `_` global variable.
+ They both need a global `_` variable, but expect different functions to be available on it. The same could be true for different versions of the
+ same library, such as lodash 3 vs lodash 4. In those situations, you can use single-spa-leaked-globals to make sure the `_` that is available
+ for app1 and app2 is the correct one.
## Limitations
+
single-spa-leaked-globals cannot change the global nature of global dependencies. Only one instance of the global variable can be on the
`window` at a time. **This means that you probably can only have one application mounted at a time that depends on that global variable.**
If two applications depend on the same global variable and are [active](/docs/configuration#activity-function) at the same time,
single-spa-leaked-globals won't work for you.
## Installation
+
### Via npm
+
```sh
npm install --save single-spa-leaked-globals
@@ -44,15 +49,18 @@ yarn add single-spa-leaked-globals
```
### Via cdn
+
You can also use single-spa-leaked-globals via CDN, ironically as a global variable itself:
+
```html
```
-Note that you should probably lock down the version of the library to avoid accidentally upgrading. See
+Note that you should probably lock down the version of the library to avoid accidentally upgrading. See
https://cdn.jsdelivr.net/npm/single-spa-leaked-globals/ to find the latest version.
## Usage
+
The single-spa-leaked-globals library is often used in conjunction with another helper library, such as
single-spa-angularjs or single-spa-backbone. As such, you'll want to
[export an array](/docs/building-applications#registered-application-lifecycle) for your lifecycle functions
@@ -89,13 +97,16 @@ export const unmount = [
```
If you're using single-spa-leaked-globals as a global variable itself:
+
```js
const leakedGlobalsLifecycles = window.singleSpaLeakedGlobals.default({
- globalVariableNames: ['_'],
-})
+ globalVariableNames: ["_"],
+});
```
## API / Options
+
single-spa-leaked-globals is called with an object with the following properties:
+
- `globalVariableNames` (required): An array of strings. Each string is the name of a global variable that should
be removed when the application is unmounted, and added back when the application is mounted.
diff --git a/versioned_docs/version-5.x/ecosystem-preact.md b/versioned_docs/version-5.x/ecosystem-preact.md
index 4ffb528f3..dd52e03cd 100644
--- a/versioned_docs/version-5.x/ecosystem-preact.md
+++ b/versioned_docs/version-5.x/ecosystem-preact.md
@@ -7,22 +7,24 @@ sidebar_label: Preact
single-spa-preact is a helper library that helps implement [single-spa registered application](configuration#registering-applications) [lifecycle functions](building-applications.md#registered-application-lifecycle) (bootstrap, mount and unmount) for for use with [Preact](https://preactjs.com/). Check out the [single-spa-preact github](https://github.com/single-spa/single-spa-preact).
## Installation
+
```sh
npm install --save preact
```
## Quickstart
+
In your project's entry file, add the following:
```js
-import preact from 'preact';
-import rootComponent from './path-to-root-component.js';
-import singleSpaPreact from 'single-spa-preact';
+import preact from "preact";
+import rootComponent from "./path-to-root-component.js";
+import singleSpaPreact from "single-spa-preact";
const preactLifecycles = singleSpaPreact({
preact,
rootComponent,
- domElementGetter: () => document.getElementById('main-content'),
+ domElementGetter: () => document.getElementById("main-content"),
});
export const bootstrap = preactLifecycles.bootstrap;
diff --git a/versioned_docs/version-5.x/ecosystem-react.md b/versioned_docs/version-5.x/ecosystem-react.md
index f77a9a420..cc4c00c80 100644
--- a/versioned_docs/version-5.x/ecosystem-react.md
+++ b/versioned_docs/version-5.x/ecosystem-react.md
@@ -24,11 +24,11 @@ Alternatively, you can use single-spa-react by adding `
```
@@ -181,8 +180,8 @@ Sharing a single instance of Vue and other common libraries is highly recommende
```js
// vue.config.js
module.exports = {
- chainWebpack: config => {
- config.externals(['vue', 'vue-router']);
+ chainWebpack: (config) => {
+ config.externals(["vue", "vue-router"]);
},
};
```
@@ -192,7 +191,7 @@ module.exports = {
```js
// webpack.config.js
module.exports = {
- externals: ['vue', 'vue-router'],
+ externals: ["vue", "vue-router"],
};
```
@@ -203,7 +202,7 @@ All options are passed to single-spa-vue via the `opts` parameter when calling `
- `Vue`: (required) The main Vue object, which is generally either exposed onto the window or is available via `require('vue')` `import Vue from 'vue'`.
- `appOptions`: (required) An object or async function which will be used to instantiate your Vue.js application. `appOptions` will pass directly through to `new Vue(appOptions)`. Note that if you do not provide an `el` to appOptions, that a div will be created and appended to the DOM as a default container for your Vue application. When `appOptions` is an async function, it receives the single-spa props as an argument (as of
single-spa-vue@2.4.0).
- `loadRootComponent`: (optional and replaces `appOptions.render`) A promise that resolves with your root component. This is useful for lazy loading.
-- `handleInstance`: (optional) A method can be used to handle Vue instance. Vue 3 brings [new instance API](https://v3.vuejs.org/guide/migration/global-api.html#a-new-global-api-createapp), and you can access *the app instance* from this, like `handleInstance: (app, props) => app.use(router)`. For Vue 2 users, a [Vue instance](https://vuejs.org/v2/guide/instance.html) can be accessed. The `handleInstance(app, props)` function receives the instance as its first argument, and single-spa props as its second argument. If handleInstance returns a promise, single-spa-vue will wait to resolve the app / parcel's `mount` lifecycle until the handleInstance promise resolves.
+- `handleInstance`: (optional) A method can be used to handle Vue instance. Vue 3 brings [new instance API](https://v3.vuejs.org/guide/migration/global-api.html#a-new-global-api-createapp), and you can access _the app instance_ from this, like `handleInstance: (app, props) => app.use(router)`. For Vue 2 users, a [Vue instance](https://vuejs.org/v2/guide/instance.html) can be accessed. The `handleInstance(app, props)` function receives the instance as its first argument, and single-spa props as its second argument. If handleInstance returns a promise, single-spa-vue will wait to resolve the app / parcel's `mount` lifecycle until the handleInstance promise resolves.
- `replaceMode`: (optional, defaults to `false`) A boolean that determines whether your root Vue component will entirely replace the container element it's mounted to. The Vue library always replaces, so to implement `replaceMode: false` a temporary `
` element is created inside of the container, so that Vue replaces that element rather than the container. Introduced in single-spa-vue@2.3.0.
To configure which dom element the single-spa application is mounted to, use [appOptions.el](https://vuejs.org/v2/api/#el):
@@ -212,8 +211,8 @@ To configure which dom element the single-spa application is mounted to, use [ap
const vueLifecycles = singleSpaVue({
Vue,
appOptions: {
- render: h => h(App),
- el: '#a-special-container',
+ render: (h) => h(App),
+ el: "#a-special-container",
},
});
```
@@ -226,8 +225,8 @@ const vueLifecycles = singleSpaVue({
async appOptions() {
return {
router: await routerFactory(),
- render: h => h(App)
- }
+ render: (h) => h(App),
+ };
},
});
```
@@ -394,10 +393,10 @@ With this directory structure (which is the Vue CLI default), the public path sh
// vue.config.js
module.exports = {
chainWebpack(config) {
- config.plugin('SystemJSPublicPathWebpackPlugin').tap((args) => {
+ config.plugin("SystemJSPublicPathWebpackPlugin").tap((args) => {
args[0].rootDirectoryLevel = 1;
return args;
});
- }
-}
+ },
+};
```
diff --git a/versioned_docs/version-5.x/ecosystem.md b/versioned_docs/version-5.x/ecosystem.md
index 6c7c42bfa..7bf8d96bb 100644
--- a/versioned_docs/version-5.x/ecosystem.md
+++ b/versioned_docs/version-5.x/ecosystem.md
@@ -7,6 +7,7 @@ sidebar_label: Overview
The single-spa ecosystem is quickly growing to support as many frameworks and build tools as possible.
## Help for frameworks
+
There is a growing number of projects that help you bootstrap, mount,
and unmount your applications that are written with popular frameworks. Feel free
to contribute to this list with your own project:
diff --git a/versioned_docs/version-5.x/faq.md b/versioned_docs/version-5.x/faq.md
index 04c37b2b5..a8a8d6dd0 100644
--- a/versioned_docs/version-5.x/faq.md
+++ b/versioned_docs/version-5.x/faq.md
@@ -140,9 +140,9 @@ Single spa supports code splits. There are so many ways to code split we won't b
- For SystemJS >= 6, use [systemjs-webpack-interop](https://github.com/joeldenning/systemjs-webpack-interop):
```js
- import { setPublicPath } from 'systemjs-webpack-interop';
+ import { setPublicPath } from "systemjs-webpack-interop";
- setPublicPath('name-of-module-in-import-map');
+ setPublicPath("name-of-module-in-import-map");
```
- For SystemJS 2-5: Find a code example [here](https://gitlab.com/TheMcMurder/single-spa-portal-example/blob/master/people/src/set-public-path.js#L3)
diff --git a/versioned_docs/version-5.x/layout-api.md b/versioned_docs/version-5.x/layout-api.md
index 8ea20b9d6..d31a62e51 100644
--- a/versioned_docs/version-5.x/layout-api.md
+++ b/versioned_docs/version-5.x/layout-api.md
@@ -134,10 +134,10 @@ In NodeJS, single-spa-layout exports the following functions as named exports. N
```js
// Works in newer versions of NodeJS
-import 'single-spa-layout';
+import "single-spa-layout";
// Works in older versions of NodeJS
-import 'single-spa-layout/dist/esm/single-spa-layout-server.min.js';
+import "single-spa-layout/dist/esm/single-spa-layout-server.min.js";
```
### constructServerLayout
@@ -145,13 +145,13 @@ import 'single-spa-layout/dist/esm/single-spa-layout-server.min.js';
The `constructServerLayout` api parses an HTML file and prepares it for rendering. This should be done once when the NodeJS server boots up, so the same serverLayout can be reused for all incoming HTTP requests.
```js
-import { constructServerLayout } from 'single-spa-layout/server';
+import { constructServerLayout } from "single-spa-layout/server";
const serverLayout = constructServerLayout({
// filepath is resolved relative to the cwd (current working directory)
// of the NodeJS process.
- filePath: "server/views/index.html"
-})
+ filePath: "server/views/index.html",
+});
// Alternatively, provide the html as a string
const serverLayout = constructServerLayout({
@@ -163,8 +163,8 @@ const serverLayout = constructServerLayout({