From 619d2addf78ac5b5268f69dcecbcc67d8667cff3 Mon Sep 17 00:00:00 2001 From: Joel Denning Date: Fri, 23 Oct 2020 16:44:05 -0600 Subject: [PATCH 1/2] Allow for using native modules instead of SystemJS --- src/instant-test/instant-test.component.js | 1 + .../registered-app.component.js | 3 +- .../root-config-guide.component.js | 3 +- src/root.component.js | 3 +- src/shared/edit-registered-app.component.js | 48 ++++++++++++++++++- src/shared/registered-app.component.js | 3 +- .../application-executable.component.js | 4 +- .../verification-steps/import-app.js | 21 ++++++++ .../lifecycles-exported.component.js | 3 +- .../mount-lifecycle.component.js | 3 +- .../view-application.component.js | 3 +- 11 files changed, 84 insertions(+), 11 deletions(-) create mode 100644 src/verify-app-guide/verification-steps/import-app.js diff --git a/src/instant-test/instant-test.component.js b/src/instant-test/instant-test.component.js index 531377f..332d436 100644 --- a/src/instant-test/instant-test.component.js +++ b/src/instant-test/instant-test.component.js @@ -15,6 +15,7 @@ export default function InstantTest(props) { name: params.get("name"), pathPrefix: "/", framework: params.get("framework") || undefined, + useNativeModules: params.get("useNativeModules") === "true", }; addApplication(app); diff --git a/src/registered-app/registered-app.component.js b/src/registered-app/registered-app.component.js index d689e05..6dd4592 100644 --- a/src/registered-app/registered-app.component.js +++ b/src/registered-app/registered-app.component.js @@ -2,6 +2,7 @@ import React, { useContext } from "react"; import { useCss } from "kremling"; import Code from "../code.component"; import { LocalStorageContext } from "../use-local-storage-data.hook"; +import { importAppCode } from "../verify-app-guide/verification-steps/import-app"; export default function RegisteredApp({ app, edit, interactive }) { const scope = useCss(css); @@ -85,7 +86,7 @@ const indentedCode = (app) => ` singleSpa.registerApplication( '${app.name}', - System.import('${app.name}'), + () => ${importAppCode(app)}, location => location.pathname.startsWith('${app.pathPrefix}') ); `; diff --git a/src/root-config-guide/root-config-guide.component.js b/src/root-config-guide/root-config-guide.component.js index 314050f..36514e6 100644 --- a/src/root-config-guide/root-config-guide.component.js +++ b/src/root-config-guide/root-config-guide.component.js @@ -7,6 +7,7 @@ import Code from "../shared/code.component"; import { sharedDepsImportMap } from "../shared/registered-app.component"; import { Link } from "react-router-dom"; import { useAppSharedDependencies } from "../shared/use-app-shared-deps.hook"; +import { importAppCode } from "../verify-app-guide/verification-steps/import-app"; export default function HtmlFile(props) { const scope = useCss(css); @@ -50,7 +51,7 @@ export default function HtmlFile(props) { const registerAppCode = ` singleSpa.registerApplication( '${application.name}', - () => System.import('${application.name}'), + () => ${importAppCode(application)}, location => location.pathname.startsWith('${application.pathPrefix}') ); diff --git a/src/root.component.js b/src/root.component.js index 496de03..212841f 100644 --- a/src/root.component.js +++ b/src/root.component.js @@ -3,6 +3,7 @@ import Playground from "./playground.component"; import useLocalStorageData from "./shared/use-local-storage-data.hook"; import { getAppNames, registerApplication, navigateToUrl } from "single-spa"; import HiddenPlayground from "./hidden-playground.component"; +import { importApp } from "./verify-app-guide/verification-steps/import-app"; export default function Root(props) { const [showPlayground, setShowPlayground] = useState(() => @@ -53,7 +54,7 @@ export default function Root(props) { /* global System */ registerApplication( application.name, - () => System.import(application.name), + () => importApp(application), (location) => location.pathname.startsWith(application.pathPrefix) ); } diff --git a/src/shared/edit-registered-app.component.js b/src/shared/edit-registered-app.component.js index c1ca4b2..0c82ef5 100644 --- a/src/shared/edit-registered-app.component.js +++ b/src/shared/edit-registered-app.component.js @@ -17,6 +17,7 @@ export default function EditRegisteredApp({ const [alertMessage, setAlertMessage] = useState(null); const [loading, setLoading] = useState(false); const [appSharedDeps, setAppSharedDeps] = useState([]); + const [useNativeModules, setUseNativeModules] = useState(false); const scope = useCss(css); const ariaPrefix = name || "new-app"; @@ -68,7 +69,13 @@ export default function EditRegisteredApp({ type="text" value={url} onChange={(evt) => setUrl(evt.target.value)} - placeholder="http://localhost:8080/app1.js" + placeholder={ + framework === "vue" + ? `http://localhost:8080/js/app.js` + : `http://localhost:8080/${ + name ? name.replace(/@/g, "").replace(/\//g, "-") : "app1" + }.js` + } aria-labelledby={urlLabel} required autoComplete="off" @@ -89,6 +96,33 @@ export default function EditRegisteredApp({ /> +
+ +