single-spa
Advanced tools
Comparing version 1.2.4 to 1.2.5
@@ -10,3 +10,3 @@ 'use strict'; | ||
function _typeof(obj) { return obj && obj.constructor === Symbol ? "symbol" : typeof obj; } | ||
function _typeof(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; } | ||
@@ -249,3 +249,3 @@ var appLocationToApp = {}; | ||
request.addEventListener('load', htmlLoaded); | ||
request.open('GET', window.location.protocol + '//' + window.location.hostname + ':' + window.location.port + '/' + app.publicRoot + '/' + app.pathToIndex); | ||
request.open('GET', window.location.protocol + '//' + window.location.hostname + ':' + window.location.port + ('/' + app.publicRoot + '/' + app.pathToIndex).replace(/\/\//g, '/')); | ||
request.send(); | ||
@@ -252,0 +252,0 @@ |
{ | ||
"name": "single-spa", | ||
"version": "1.2.4", | ||
"version": "1.2.5", | ||
"description": "Multiple applications, one page", | ||
@@ -24,4 +24,4 @@ "main": "dist/single-spa.js", | ||
"devDependencies": { | ||
"babel-cli": "6.0.14", | ||
"babel-preset-es2015": "6.0.14" | ||
"babel-cli": "6.0.15", | ||
"babel-preset-es2015": "6.0.15" | ||
}, | ||
@@ -28,0 +28,0 @@ "publishConfig": { |
# single-spa | ||
Multiple applications all lazily loaded and mounted/unmounted in the same single page application (SPA). The apps can be deployed independently to your web server of choice, lazy-loaded onto the page independently, and nested. | ||
Multiple applications all lazily loaded and mounted/unmounted in the same single page application (SPA). The apps can be deployed independently to your web server of choice, lazy-loaded onto the page independently, and nested. Single-spa also allows for **service oriented javascript**, where a "service" (a shared es6 module) is a singleton that each app can call, without resorting to shared libraries that can be out of sync across apps. | ||
In this context, an application is an html document that pulls in JS, CSS, and more HTML. This means that many pre-existing applications do not need to change at all in order to work with single-spa. | ||
In this context, an application is an html document that pulls in JS, CSS, and more HTML. This means that many pre-existing applications do not need to change at all in order to work with single-spa. You just need to add a configuration file on top of your existing SPA. | ||
@@ -32,3 +32,2 @@ ## View the demo! | ||
</script> | ||
<base href="/"></base> | ||
</head> | ||
@@ -48,5 +47,5 @@ </html> | ||
### Configuring JSPM apps | ||
From your root app, | ||
[single-spa-jspm](https://github.com/joeldenning/single-spa-jspm) is an actively maintained project that eases the burden of configuring jspm apps. To use it, run the following in your root app's directory | ||
`jspm install npm:single-spa-jspm` | ||
and then add the following to your single-spa.config.js: | ||
and then add the following to the jspm app's single-spa.config.js: | ||
``` | ||
@@ -59,4 +58,21 @@ import { defaultJspmApp } from "single-spa-jspm"; | ||
So far, webpack has not required any special configuration to work in an SSPA environment. It works out of the box! So no need to add a "lifecycle" for webpack in your single-spa.config.js file. | ||
### Configuring React apps | ||
[single-spa-react](https://github.com/joeldenning/single-spa-react) is an actively maintained project that eases the burden of configuring react apps. To use it, run the following in your root app's directory | ||
`jspm install npm:single-spa-react` | ||
and then add the following to your single-spa.config.js: | ||
``` | ||
import { defaultReactApp } from "single-spa-react"; | ||
export const publicRoot = '...'; | ||
export const pathToIndex = 'index.html'; | ||
const reactApp = defaultReactApp({ | ||
rootElementGetter: function() { | ||
return document.querySelector('#root-react-element'); | ||
} | ||
}); | ||
export const lifecycles = [reactApp, ...(any other plugins)...]; | ||
``` | ||
### Configuring Angular apps | ||
From your root app, | ||
[single-spa-angular1](https://github.com/joeldenning/single-spa-angular1) is an actively maintained project that eases the burden of configuring Angular apps. To use it, run the following in your root app's directory | ||
`jspm install npm:single-spa-angular1` | ||
@@ -76,4 +92,14 @@ and then add the following to your single-spa.config.js | ||
``` | ||
### Configuring apps that leak globals | ||
[single-spa-globals](https://github.com/joeldenning/single-spa-globals) is an actively maintained project that eases the burden of configuring apps that leak globals. To use it, run the following in your root app's directory | ||
`jspm install npm:single-spa-globals` | ||
and then add the following to your single-spa.config.js | ||
``` | ||
import { appWithGlobals } from "single-spa-globals"; | ||
export const publicRoot = '....'; | ||
export const pathToIndex = 'index.html'; | ||
export const lifecycles = [...(any other plugins)..., appWithGlobals(['app1', 'globalVar1', 'anotherGlobal'])] | ||
``` | ||
### Read the examples | ||
So right now it's still somewhat alpha and so the best thing to do is look at the [examples repository](https://github.com/joeldenning/single-spa-examples). Especially the following files: | ||
There is also an [examples repository](https://github.com/joeldenning/single-spa-examples) that shows several apps working great in a single-spa environment. The following files are a good place to start: | ||
- [The index.html file](https://github.com/joeldenning/single-spa-examples/blob/master/index.html) | ||
@@ -83,5 +109,5 @@ - [The root app](https://github.com/joeldenning/single-spa-examples/blob/master/bootstrap.js) | ||
Also note that it requires that as of 10/19/15, the root app that loads all other apps must be written with JSPM. The goal is to move away from that towards the [whatwg/loader standard](https://github.com/whatwg/loader) or maybe towards no loader standard at all (which would offload all of the loading work to the user). | ||
Also note that it requires that as of 11/1/15, the root app that loads all other apps must be written with JSPM. The goal is to move away from that towards the [whatwg/loader standard](https://github.com/whatwg/loader), probably polyfilled with the [es6-module-loader](https://github.com/ModuleLoader/es6-module-loader). | ||
## Things that are not supported | ||
- Single Spa is the one who controls the `<base>` tag, which means that apps should not control it. single-spa-angular1 makes it possible for angular to still work (even with History API pretty urls!) without the angular app putting a `<base>` tag in the app's index.html. |
@@ -221,3 +221,3 @@ let appLocationToApp = {}; | ||
request.addEventListener('load', htmlLoaded); | ||
request.open('GET', `${window.location.protocol}//${window.location.hostname}:${window.location.port}/${app.publicRoot}/${app.pathToIndex}`); | ||
request.open('GET', `${window.location.protocol}//${window.location.hostname}:${window.location.port}` + `/${app.publicRoot}/${app.pathToIndex}`.replace(/\/\//g, '/')); | ||
request.send(); | ||
@@ -224,0 +224,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
68312
109