Adding Applications for 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. Add any additional applications that you need to the manifest file and save the changes.
  4. Add the new applications declared in the manifest file to the code repository.
    • If you’re using source code, then add the package.json file to <application.path>/package.json.

      For example, <repository-root>/js-storefront/some-subdirectory/app2/package.json

    • If you’re using a prebuilt application, then add your compiled application files, including index.html, to <application.path>/dist/<application.name>.

      For example, <repository-root>/js-storefront/some-subdirectory/app2/dist/app2/index.html.

    • 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.custo-project-env-public.model-t.cc.commerce.ondemand.com.
    • For blue and green deployments, the JavaScript Storefront can 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.
  5. To apply the changes, create a build.

    The build process 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.

    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.