Announcements
Track Storefront Next Activity with Analytics
CLI Reference
B2C Commerce Release Notes
Ask the Community
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:
1pnpm dev # Start the development server
2pnpm build # Create a production build
3pnpm start # Preview the production build locally
4pnpm push # Deploy to Managed RuntimeFor 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 listYou can also view all available commands and options:
1pnpm sfnext --help
2pnpm sfnext <command> --helpThis 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
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-storefrontFor all other commands, use pnpm sfnext from within your project.
| Command | package.json Script | Description |
|---|---|---|
create-storefront | — | Scaffold a new storefront project from a template. |
dev | pnpm dev | Start the development server with hot module replacement. |
preview | pnpm start | Preview a production build locally. |
push | pnpm push | Build a bundle and deploy it to Managed Runtime. |
create-bundle | — | Create a deployment bundle without pushing. |
extensions | — | Manage 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:
1pnpm dlx @salesforce/storefront-next-dev create-storefront [options]| Option | Description |
|---|---|
-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, --verbose | Enable verbose output. |
Create a storefront interactively:
1pnpm dlx @salesforce/storefront-next-dev create-storefrontCreate a storefront with a specific name:
1pnpm dlx @salesforce/storefront-next-dev create-storefront --name my-storefrontAfter the command completes, follow the on-screen instructions to install dependencies and start developing:
1cd my-storefront
2pnpm install
3pnpm build
4pnpm devFor 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.
1pnpm devOr with options:
1pnpm sfnext dev [options]| Option | Description | Default |
|---|---|---|
-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:
1pnpm devStart the dev server on a custom port:
1pnpm sfnext dev --port 3000Start with the Node.js debugger attached:
1pnpm dev:debug/mobify/proxy/api so that you can develop against live data without CORS issues..env file.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 startOr with options:
1pnpm sfnext preview [options]| Option | Description | Default |
|---|---|---|
-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:
1pnpm startPreview on a custom port:
1pnpm sfnext preview --port 8080| Feature | dev | preview |
|---|---|---|
| Build type | On-the-fly via Vite | Pre-built production bundle |
| HMR | Yes | No |
| Static asset serving | Vite handles | Express with compression |
| Performance | Optimized for speed of iteration | Reflects 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.
1pnpm pushOr with options:
1pnpm sfnext push [options]| Option | Description | Default |
|---|---|---|
--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, --wait | Wait 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 to specify a custom path.--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:
1pnpm build
2pnpm pushDeploy to a specific environment and wait for completion:
1pnpm sfnext push --environment staging --waitDeploy with an API key:
1pnpm sfnext push --api-key your-api-keyCreate 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]| Option | Description | Default |
|---|---|---|
-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).1pnpm build
2pnpm sfnext create-bundle -d . -o ./my-bundleManage feature extensions for your storefront project. Extensions add pre-built functionality, such as store locators or theme switchers.
1pnpm sfnext extensions <subcommand> [options]List all extensions currently installed in your project.
1pnpm sfnext extensions list [options]| Option | Description | Default |
|---|---|---|
-d, --project-directory <dir> | Path to the project directory. | Current directory |
1pnpm sfnext extensions listInstall 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]| Option | Description | Default |
|---|---|---|
-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, --verbose | Enable 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:
1pnpm sfnext extensions installInstall a specific extension by marker:
1pnpm sfnext extensions install -e SFDC_EXT_STORE_LOCATORRemove one or more installed extensions from your project. The CLI automatically detects and removes dependent extensions.
1pnpm sfnext extensions remove [options]| Option | Description | Default |
|---|---|---|
-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, --verbose | Enable verbose output. |
Remove extensions interactively:
1pnpm sfnext extensions removeRemove specific extensions by marker:
1pnpm sfnext extensions remove -e SFDC_EXT_STORE_LOCATORScaffold 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]| Option | Description | Default |
|---|---|---|
-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. |
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.mdSeveral CLI commands read configuration from environment variables defined in your .env file.
| Variable | Used By | Description |
|---|---|---|
SFCC_MRT_PROJECT | push, create-bundle | Project slug for Managed Runtime. |
SFCC_MRT_ENVIRONMENT | push | Deployment target environment. |
SFCC_MRT_API_KEY | push | API key for MRT authentication. |
SFCC_PROJECT_DIRECTORY | All commands | Project directory (alternative to --project-directory flag). |
MRT_PROJECT | push, create-bundle | Legacy alias for SFCC_MRT_PROJECT. |
MRT_TARGET | push | Legacy alias for SFCC_MRT_ENVIRONMENT. |
PUBLIC__app__commerce__api__shortCode | dev, preview | B2C Commerce API short code. |
PUBLIC__app__commerce__api__organizationId | dev, preview | B2C Commerce organization ID. |
PUBLIC__app__commerce__api__clientId | dev, preview | B2C Commerce client ID. |
PUBLIC__app__commerce__api__siteId | dev, preview | B2C Commerce site ID. |