Back to Spree

create-spree-app

packages/create-spree-app/README.md

5.4.23.4 KB
Original Source

create-spree-app

Scaffold a new Spree Commerce project with a single command. Backend runs via Docker using pre-built images, with a full Rails app included for customization.

Quick Start

bash
npx create-spree-app my-store

This will walk you through an interactive setup:

  1. Include Next.js Storefront (default: yes)
  2. Optionally load sample data (products, categories, images)
  3. Optionally start Docker services immediately

CLI Flags

For non-interactive usage:

bash
npx create-spree-app my-store --no-storefront --no-sample-data --no-start
FlagDescription
--no-storefrontSkip Next.js storefront setup
--no-sample-dataSkip loading sample products
--no-startDon't start Docker services
--port <number>Port for the Spree backend (default: 3000)
--use-npmUse npm as package manager
--use-yarnUse yarn as package manager
--use-pnpmUse pnpm as package manager

What You Get

my-store/
├── docker-compose.yml        # Spree backend (prebuilt image) + Postgres + Redis
├── docker-compose.dev.yml    # Alternative: build from local backend/
├── .env                      # SECRET_KEY_BASE, SPREE_PORT
├── .gitignore
├── package.json              # @spree/cli + convenience scripts
├── README.md
├── backend/                  # Full Rails app (from spree/spree-starter)
│   ├── Gemfile
│   ├── Dockerfile
│   ├── config/
│   ├── app/
│   └── ...
└── apps/
    └── storefront/           # Next.js app (unless --no-storefront)

Prerequisites

After Setup

Admin Dashboard

Open http://localhost:3000/admin

Store API

http://localhost:3000/api/v3/store

Storefront

bash
cd my-store/apps/storefront
npm run dev

Open http://localhost:3001

Customizing the Backend

The backend/ directory contains a full Rails application with Spree installed. By default, the project uses a prebuilt Docker image. To switch to building from your local backend:

bash
npx spree eject

This rebuilds the Docker image from backend/ and restarts services. You can then:

  • Add gems to backend/Gemfile
  • Override models with decorators in backend/app/models/
  • Add controllers in backend/app/controllers/
  • Configure Spree in backend/config/initializers/spree.rb
  • Add migrations with cd backend && bin/rails generate migration

Useful Commands

Run these from your project directory (powered by @spree/cli):

CommandDescription
npm run devStart backend services and stream logs
npm run stopStop backend services
npm run ejectSwitch from prebuilt image to local backend builds
npm run updatePull latest Spree image and restart
npm run logsView backend logs
npm run consoleRails console

You can also use the CLI directly for additional commands:

bash
npx spree user create          # Create an admin user
npx spree api-key create       # Create an API key
npx spree api-key list         # List API keys

Learn More

License

MIT