Search code examples
create-react-appsingle-spa

single spa Microfrontend and CRA application


Can we connect to app created using Create React App with single-spa MFE in root config import map file? If yes then what is the entry file which needs to be added in index.ejs file in single-spa root app?

Example:

 <% if (isLocal) { %>
  <script type="systemjs-importmap">
    {
      "imports": {
        "@org1/root-config": "//localhost:9000/org1-root-config.js",
         "react-app": "<what's the entry file path to be given here?>",
      }
    }
  </script>
  <% } %>

Note: I am not converting CRA app to single-SPA here.

If not, whats the recommended approach to access CRA in single-spa code? Please help me fix this issue.


Solution

  • What you ask is not possible. If you want to load an application using single-spa, you must follow single-spa rules. You cannot simply say "I won't convert my app to work for single-spa but I want it to work anyway".

    If you want to show a non-converted app inside the root, use an <iframe> HTML element and load the application by URL as an embedded web page.