Add Applications to JavaScript Storefronts

The JavaScript storefront sample repository includes a single storefront application. You can add applications and the packages that support those applications to your cloned code repository.

Prerequisites

  • You cloned the 2105-spartacus branch of the sample repository. For more information, see Commerce Cloud Repository.
  • You followed the instructions in the readme file to prepare the files.

Procedure

  1. Open the code repository.
  2. Navigate to root/js-storefront and open the JavaScript storefront manifest file.
  3. Enable SAP Commerce Cloud, composable storefront by adding the following data to the manifest file:
    {
        "applications": [
            {
                "name": "yourAppName",
                "path": "yourAppName",
                .
                .
                "enabledRepositories": [
                    "spartacus-6"
                ]
            },
         ...
        ]
    }
  4. Optional: Add any additional applications that you need to the manifest file and save the changes.
  5. Add the new applications declared in the manifest file to the code repository.
    • If you're using source code, add the following files and folders to your repository:
      • Add the <package.json> file: application.path/package.json.
      • Make sure to include the <yarn.lock> file: application.path/yarn.lock. This ensures reproducible builds for your JavaScript applications.
      • Add the <src> folder: application.path/src.
      Here's an example of an application.path with a <package.json> file added to the repository:
      repository-root/js-storefront/some-subdirectory/app2/package.json
    • If you’re using a prebuilt application, ensure your output files, including index.html, are saved in <application.path>/dist/<application.name>. For example:
      repository-root/js-storefront/some-subdirectory/app2/dist/app2/index.html

      The index.html file of each application must contain the following placeholder:

      <meta name="occ-backend-base-url" content="OCC_BACKEND_BASE_URL_VALUE" />

      This placeholder is replaced with the real API aspect external URL at application startup.

    • To explicitly configure the back-end URL for each of your applications, use the ccv2.occ.backend.base.url.<$jsapp>.value service property in the JavaScript storefront service configuration. For example:
      ccv2.occ.backend.base.url.spartacusstore.value=https://api.custom-project-env-public.model-t.cc.commerce.ondemand.com
    • If you do not explicitly configure the back-end URL for each of your applications, JavaScript storefronts can use blue and green deployments. This allows the storefront to have different types of endpoints:
      • Green: JavaScript storefront automatically adds a green API endpoint. The JavaScript storefront does not startup if there is no endpoint.
      • Blue: JavaScript storefront automatically adds a default API endpoint.
  6. To apply the changes, create a build.

    The build process then automatically builds all JavaScript applications provided in the SAP Commerce Cloud code repository.

    For each application defined in manifest.json, the build process checks whether the <application.path>/dist directory exists. If it doesn’t exist, the build process runs the following commands in the <application.path> directory:

    For Client-Side Rendering (CSR):

    • yarn install - downloads dependencies that are declared in package.json,
    • yarn build - runs the build command that is declared in package.json.

    For Server Side Rendering (SSR):

    • yarn install - downloads dependencies declared in package.json,
    • yarn build:ssr - runs the build command that is declared in package.json.

    Otherwise, if the <application.path>/dist does exist, the build process assumes that this directory contains a JavaScript storefront that is already built and it skips the build.