JSS initializer parameters

Version:

This topic lists all valid parameters you can include when using npx to initialize a local JSS application. Using them will reduce the number of questions you're asked while running the JSS initializer.

Note

These parameters are not available when using other package managers such as npm or yarn to initialize a JSS app.

The base app template and add-ons

Every JSS app is based on a starter template, which determines the framework that powers the app. The templates parameter accepts a comma-separated string list containing the name of the base app template and the names of any add-ons you want the app to include.

The templates list must include one of the following base app templates names:

  • nextjs

  • angular

Depending on the chosen base app, you also need to include one of the following SitecoreAI add-ons:

  • node-xmcloud-proxy - required for non-Next.js (such as Angular) apps to connect to SitecoreAI.

  • nextjs-xmcloud - required for Next.js apps to connect to SitecoreAI.

Note

If you only specify a base app template, the initializer will ask you whether you're building for SitecoreAI and, if so, it will install the required add-on automatically.

XM Cloud is now SitecoreAI

Some code examples, images, and UI labels may still use XM Cloud while engineering assets are being updated.

Lastly, you can specify add-ons relevant to the chosen base template, such as:

  • nextjs-sxa - an important add-on for Next.js JSS apps for SitecoreAI. It includes configurations for Next.js headless projects as well as Sitecore Experience Accelerator (SXA) example components. You should always include this add-on when working with the Next.js starter template.

  • nextjs-multisite - an optional add-on that includes an example setup for hosting multiple sites from a single Next.js application.

Note

The nextjs-styleguide add-on is not relevant for SitecoreAI apps, and it is not compatible with nextjs-sxa, so you can ignore it.

The following example command initializes a Next.js app with the SitecoreAI and SXA add-ons.

npx create-sitecore-jss --templates nextjs,nextjs-xmcloud,nextjs-sxa

When placing the templates parameter first like this, you can omit --templates and write the list as is, such as:

npx create-sitecore-jss nextjs,nextjs-xmcloud,nextjs-sxa
XM Cloud is now SitecoreAI

Some code examples, images, and UI labels may still use XM Cloud while engineering assets are being updated.

Main parameters

All of these parameters are optional, but using them lets you quickly create apps based on common settings without having to answer all the standard questions during the initialization process.

Note

All of these parameters accept string values.

Parameter

Description

appName

The name of your JSS application.

Default: sitecore-jss-app

destination

Path or directory for the new application.

If you provide a path that already contains files, the initializer will warn you and confirm that you want to proceed. For the files potentially changed by the initializer, you'll have the option to approve changes for each file, skip individual files, approve changes to all files, or abort the process.

Using the initializer in a non-empty destination helps you apply add-on templates to an existing JSS app.

Default: <current-directory-path>/<base-template-name>

fetchWith

Method for fetching data. You can choose REST or GraphQL, but for SitecoreAI we strongly recommend using GraphQL in all JSS apps.

Default: GraphQL

prerender

Only available if using the nextjs template. Prerendering method for the application. Choose between static site generation (SSG) and server-side rendering (SSR).

Default: SSG

language

Only valid if using the nextjs-styleguide add-on. Language and locale code. For example, es-MX.

Default: da-DK

hostName

The hostname of your Sitecore instance.

Default: <appName>.dev.local

For example, if you use the following command, you won't be prompted to choose templates, an app name, or a fetch method while initializing your app:

npx create-sitecore-jss nextjs,nextjs-xmcloud,nextjs-multisite --appName my-nextjs-app --fetchWith GraphQL
XM Cloud is now SitecoreAI

Some code examples, images, and UI labels may still use XM Cloud while engineering assets are being updated.

Optional parameters

These optional parameters can be added to your npx command to modify the JSS app initialization process, based on your preferences.

Note

These parameters do not take a value. Including one of them will apply an effect as described in the following table.

Parameter

Effect when included

appPrefix

Instructs the application to do the following:

  • Prefixes all templates with your app's appName argument. Ordinarily, deploying multiple templates with the same name will cause conflict errors when using strongly typed GraphQL queries.

  • Prefixes all placeholders with your app's appName argument. If you have multiple JSS apps deployed to SitecoreAI, enabling this option ensures that when you add components to placeholders in SitecoreAI, you can only choose components for the current site.

force

Skips all initializer questions related to file system operations, choosing the default option for each.

silent

Hides all log messages while the initializer is running.

prePushHook

Each time you push changes to your remote repo, runs a linting script that validates all TypeScript types and code formatting.

yes

Skips all initializer questions related to CLI argument values, choosing the default option for each.

--xmcloud

The initializer uses the nextjs-xmcloud template to scaffold the JSS application.

XM Cloud is now SitecoreAI

Some code examples, images, and UI labels may still use XM Cloud while engineering assets are being updated.

If you have suggestions for improving this article, let us know!