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.

Running CLI Commands 

Using Project package.json Scripts 

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

1pnpm dev        # Start the development server
2pnpm build      # Create a production build
3pnpm start      # Preview the production build locally
4pnpm push       # Deploy to Managed Runtime

Running Commands Directly 

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:

1pnpm sfnext <command> [options]

For example:

1pnpm sfnext dev --port 3000
2pnpm sfnext extensions list

You can also view all available commands and options:

1pnpm sfnext --help
2pnpm sfnext <command> --help

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.

Important

Creating a Storefront Without a Project 

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:

1pnpm dlx @salesforce/storefront-next-dev create-storefront

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

Commands 

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).

create-storefront 

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:

1pnpm dlx @salesforce/storefront-next-dev create-storefront [options]

Options 

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.

Examples 

Create a storefront interactively:

1pnpm dlx @salesforce/storefront-next-dev create-storefront

Create a storefront with a specific name:

1pnpm dlx @salesforce/storefront-next-dev create-storefront --name my-storefront

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

1cd my-storefront
2pnpm install
3pnpm build
4pnpm dev

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

dev 

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.

1pnpm dev

Or with options:

1pnpm sfnext dev [options]

Options 

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

Examples 

Start the dev server:

1pnpm dev

Start the dev server on a custom port:

1pnpm sfnext dev --port 3000

Start with the Node.js debugger attached:

1pnpm dev:debug

What the Dev Server Does 

  • 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.

preview / start 

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.

1pnpm start

Or with options:

1pnpm sfnext preview [options]

Options 

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

Examples 

Preview the production build:

1pnpm start

Preview on a custom port:

1pnpm sfnext preview --port 8080

How Preview Differs from Dev 

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

push 

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

1pnpm push

Or with options:

1pnpm sfnext push [options]

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

Authentication 

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.

Setting Up MRT Resources 

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

Examples 

Build and deploy to MRT:

1pnpm build
2pnpm push

Deploy to a specific environment and wait for completion:

1pnpm sfnext push --environment staging --wait

Deploy with an API key:

1pnpm sfnext push --api-key your-api-key

create-bundle 

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.

1pnpm sfnext create-bundle -d <project-directory> [options]

Options 

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

Output 

The command generates two files in the output directory:

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

Example 

1pnpm build
2pnpm sfnext create-bundle -d . -o ./my-bundle

extensions 

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

1pnpm sfnext extensions <subcommand> [options]

extensions list 

List all extensions currently installed in your project.

1pnpm sfnext extensions list [options]
OptionDescriptionDefault
-d, --project-directory <dir>Path to the project directory.Current directory

Example 

1pnpm sfnext extensions list

extensions install 

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.

1pnpm sfnext extensions install [options]
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.

Examples 

Install an extension interactively:

1pnpm sfnext extensions install

Install a specific extension by marker:

1pnpm sfnext extensions install -e SFDC_EXT_STORE_LOCATOR

extensions remove 

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

1pnpm sfnext extensions remove [options]
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.

Example 

Remove extensions interactively:

1pnpm sfnext extensions remove

Remove specific extensions by marker:

1pnpm sfnext extensions remove -e SFDC_EXT_STORE_LOCATOR

extensions create 

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

1pnpm sfnext extensions create [options]
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.

Example 

1pnpm sfnext extensions create --name "Store Locator" --description "Find nearby stores"

The generated directory structure:

1src/extensions/store-locator/
2  components/
3  hooks/
4  locales/
5  routes/
6  README.md

Environment Variables 

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.

See Also