Command-Line Interface (CLI) Reference

The sfnext CLI is your primary tool for developing and deploying Storefront Next projects. It’s provided by the @salesforce/storefront-next-dev package, which is installed as a project dependency—not globally.

Storefront Next projects include pre-configured scripts in package.json for common tasks:

For commands that don’t have a package.json script, or when you need to pass specific options, run pnpm sfnext from your project’s root directory:

For example:

You can also view all available commands and options:

This works because pnpm automatically resolves binaries installed in your project’s node_modules/.bin. Running sfnext this way ensures the CLI version always matches your project’s dependencies.

Don’t install @salesforce/storefront-next-dev globally. Always run commands from within your project directory so that the CLI version stays in sync with your dependencies.

The create-storefront command is the one exception—it runs before a project exists, so there’s no local node_modules to resolve from. For this command, use pnpm dlx to download and execute the package directly:

For all other commands, use pnpm sfnext from within your project.

Commandpackage.json ScriptDescription
create-storefrontScaffold a new storefront project from a template.
devpnpm devStart the development server with hot module replacement.
previewpnpm startPreview a production build locally.
pushpnpm pushBuild a bundle and deploy it to Managed Runtime.
create-bundleCreate a deployment bundle without pushing.
extensionsManage feature extensions (install, remove, create, list).

Scaffold a new Storefront Next project. The command clones a template repository, walks you through extension selection, and configures your environment variables.

Because this command creates a new project, it’s the one CLI command you run before a project exists. Use pnpm dlx to download and run it without a prior installation:

OptionDescription
-n, --name <name>Name for the storefront. Skips the interactive prompt.
-t, --template <template>Template URL or local path (for example, a GitHub URL or file:///path/to/template).
-l, --local-packages-dir <dir>Local monorepo packages directory. Used with file:// templates to pre-fill dependency paths.
-v, --verboseEnable verbose output.

Create a storefront interactively:

Create a storefront with a specific name:

After the command completes, follow the on-screen instructions to install dependencies and start developing:

For a walkthrough of creating a storefront with the CLI, see Explore Storefront Next Code Locally.

Start a local development server powered by Vite with full server-side rendering (SSR) support. The server includes hot module replacement (HMR) for both client and server code, and an API proxy to B2C Commerce.

Or with options:

OptionDescriptionDefault
-d, --project-directory <dir>Path to the project directory.Current directory
-p, --port <port>Port number for the dev server.5173

Start the dev server:

Start the dev server on a custom port:

Start with the Node.js debugger attached:

  • Runs Vite in middleware mode within an Express server for full SSR support.
  • Proxies B2C Commerce API requests through /mobify/proxy/api so that you can develop against live data without CORS issues.
  • Loads environment variables from your .env file.
  • Prints your Commerce API configuration (short code, organization ID, site ID) at startup.

Start a local server that serves your production build. Use this to test production behavior before deploying. If no build exists, the command automatically runs pnpm build first.

The CLI command is preview. In package.json, it’s mapped to pnpm start.

Or with options:

OptionDescriptionDefault
-d, --project-directory <dir>Path to the project directory.Current directory
-p, --port <port>Port number for the preview server.3000

Preview the production build:

Preview on a custom port:

Featuredevpreview
Build typeOn-the-fly via VitePre-built production bundle
HMRYesNo
Static asset servingVite handlesExpress with compression
PerformanceOptimized for speed of iterationReflects production behavior

Create a deployment bundle from your production build and push it to Managed Runtime (MRT). You must build your project before running this command.

Or with options:

OptionDescriptionDefault
--project-directory <dir>Path to the project directory.Current directory
-b, --build-directory <dir>Path to the build output directory.Auto-detected
-m, --message <message>Descriptive message for the bundle.git branch:commit
-p, --project <slug>Unique project identifier on Managed Runtime.From SFCC_MRT_PROJECT or MRT_PROJECT env var
-e, --environment <target>Target environment to deploy to.From SFCC_MRT_ENVIRONMENT or MRT_TARGET env var
-w, --waitWait for the deployment to finish before exiting.false
--api-key <key>API key for MRT authentication.From SFCC_MRT_API_KEY env var
--credentials-file <file>Path to the MRT credentials file.From MRT_CREDENTIALS_FILE env var
--cloud-origin <origin>MRT API origin URL.Production default
--config <path>Path to dw.json config file.Auto-discovered from project directory
-i, --instance <name>Named instance from config file.From SFCC_INSTANCE env var

Authenticate with Managed Runtime using one of these methods:

  • Credentials file (default): The CLI reads stored credentials automatically. Use --credentials-file to specify a custom path.
  • API key: Pass --api-key on the command line or set the SFCC_MRT_API_KEY environment variable.

Before you can deploy, you need a Managed Runtime project and SLAS client credentials. Use the B2C Developer Tooling CLI to create these resources.

Build and deploy to MRT:

Deploy to a specific environment and wait for completion:

Deploy with an API key:

Create a deployment bundle and save it to disk without pushing to Managed Runtime. This is useful for inspecting bundle contents or integrating with custom deployment pipelines.

OptionDescriptionDefault
-d, --project-directory <dir>(Required) Path to the project directory.
-b, --build-directory <dir>Path to the build output directory.Auto-detected
-o, --output-directory <dir>Directory where bundle files are written..bundle
-m, --message <message>Descriptive message for the bundle.git branch:commit
-s, --project-slug <slug>Unique project identifier on Managed Runtime.From .env MRT_PROJECT or package.json name

The command generates two files in the output directory:

  • bundle.tgz — The compressed deployment bundle.
  • bundle.json — Bundle metadata (message, SSR parameters, file sizes).

Manage feature extensions for your storefront project. Extensions add pre-built functionality, such as store locators or theme switchers.

List all extensions currently installed in your project.

OptionDescriptionDefault
-d, --project-directory <dir>Path to the project directory.Current directory

Install an extension from a source template repository. The CLI clones the source repository, lets you select an extension, and copies the extension files into your project.

OptionDescriptionDefault
-d, --project-directory <dir>Path to the target project directory.Current directory
-e, --extension <extension>Extension marker value to install (for example, SFDC_EXT_STORE_LOCATOR). Skips the interactive prompt.
-s, --source-git-url <url>Git URL of the source template that contains extensions.Default Storefront Next template
-v, --verboseEnable verbose output.

If the extension has dependencies on other extensions, the CLI detects them and installs the full dependency chain in the correct order.

Install an extension interactively:

Install a specific extension by marker:

Remove one or more installed extensions from your project. The CLI automatically detects and removes dependent extensions.

OptionDescriptionDefault
-d, --project-directory <dir>Path to the project directory.Current directory
-e, --extensions <extensions>Comma-separated list of extension markers to remove (for example, SFDC_EXT_STORE_LOCATOR,SFDC_EXT_THEME_SWITCHER). Skips the interactive prompt.
-v, --verboseEnable verbose output.

Remove extensions interactively:

Remove specific extensions by marker:

Scaffold a new extension in your project. This command creates the extension directory structure with placeholder folders for components, hooks, locales, and routes.

OptionDescriptionDefault
-p, --project-directory <dir>Path to the project directory.Current directory
-n, --name <name>Name of the extension (for example, "My Extension").
-d, --description <description>Description of the extension.

The generated directory structure:

Several CLI commands read configuration from environment variables defined in your .env file.

VariableUsed ByDescription
SFCC_MRT_PROJECTpush, create-bundleProject slug for Managed Runtime.
SFCC_MRT_ENVIRONMENTpushDeployment target environment.
SFCC_MRT_API_KEYpushAPI key for MRT authentication.
SFCC_PROJECT_DIRECTORYAll commandsProject directory (alternative to --project-directory flag).
MRT_PROJECTpush, create-bundleLegacy alias for SFCC_MRT_PROJECT.
MRT_TARGETpushLegacy alias for SFCC_MRT_ENVIRONMENT.
PUBLIC__app__commerce__api__shortCodedev, previewB2C Commerce API short code.
PUBLIC__app__commerce__api__organizationIddev, previewB2C Commerce organization ID.
PUBLIC__app__commerce__api__clientIddev, previewB2C Commerce client ID.
PUBLIC__app__commerce__api__siteIddev, previewB2C Commerce site ID.