Skip to main content

Deploy a template

This tutorial gets a Hydrogen storefront running from a starter template. You create the storefront from your Shopify store, deploy it to a host, and then set up a local copy to work on.


In this tutorial, you'll learn how to do the following tasks:

  • Create a storefront from a starter template, and deploy it to Oxygen or Vercel.
  • View your deployed storefront, and share it with others.
  • Set up a local copy of your storefront that reads from your store.
  • Find the parts of the template that fetch data, handle requests, and manage the cart.

  • A Shopify store that you can connect a storefront to, and a staff account with permission to manage apps and sales channels.
  • Install Node.js. The React Router template needs version 22 or 24, and Vercel Shop needs version 24.
  • For the React Router template, a GitHub account. Shopify creates the repository for your storefront in it.
  • For Vercel Shop, a Vercel account, a GitHub, GitLab, or Bitbucket account, and pnpm version 12.

Anchor to Step 1: Create and deploy your storefrontStep 1: Create and deploy your storefront

You can start from one of two templates that are built on Hydrogen. Shopify maintains the React Router template, and Vercel maintains Vercel Shop. Each one comes with a home page, collection pages, product pages, search, and a cart already built. The React Router template also includes customer accounts, analytics, and a consent banner. Vercel Shop includes customer accounts and Shopify analytics too, but you need to enable them to use them.

TemplateFrameworkHosting
React RouterReact Router 7Oxygen
Vercel ShopNext.js 16 App RouterVercel

Pick the template that matches your framework, and follow its steps:

You create the storefront in the Hydrogen channel in your Shopify admin. Shopify creates a GitHub repository from the template, connects it to your store, and deploys it to Oxygen every time you push.

  1. Click Deploy to Oxygen:

    Deploy the React Router template to Oxygen

    Your Shopify admin opens at the Hydrogen channel. If you haven't installed the Hydrogen channel yet, then install it when the admin asks you to. The admin then opens the page for creating a storefront.

  2. In Storefront name, enter a name for your storefront. You can change the name later.

  3. Under Deployment setup, keep Set up GitHub continuous deployment now selected.

  4. If you haven't connected GitHub to your store before, then click Connect GitHub, and install the Shopify GitHub app on the account or organization that you want to use.

  5. Select your GitHub account or organization. In Find or create a repository, enter a name for your repository, and then select Create followed by the name.

    The repository is private unless you select the checkbox to make it public. Shopify adds the template only to a new repository, so don't select an existing one.

  6. Click Create.

    Shopify generates your store's Storefront API and Customer Account API tokens, creates your storefront's environments, and creates the repository with the template and a GitHub Actions workflow. The workflow deploys your storefront to Oxygen.

  7. Wait for the first deployment to finish. Your storefront's overview page shows that the storefront is building. To follow its progress, click View GitHub Actions. When the deployment finishes, the overview page shows your storefront's URL.

Open the URL to see your storefront. It shows your store's products, and the checkout button in the cart opens your store's checkout.

Oxygen environments are private by default, so only staff who are logged in to your store can open the URL. To show your storefront to someone else, share a deployment with a link, or make the environment public. Development stores and stores on a trial plan can't have public environments.


Anchor to Step 2: Set up your local copyStep 2: Set up your local copy

To work on the code, clone the repository that you created in Step 1, and install dependencies:

Terminal

git clone <your-repository-url> my-store
cd my-store
npm install
git clone <your-repository-url> my-store
cd my-store
pnpm install

Your hosted storefront already has your store's credentials, but your local copy doesn't. Add them as described for your template.

The private Storefront API token is server-only. Never expose it to the browser, and never give it a browser prefix like NEXT_PUBLIC_.

Anchor to React Router on OxygenReact Router on Oxygen

Oxygen keeps your storefront's environment variables in the Shopify admin. To copy them to your local copy, run the following commands from your project's directory. link connects the directory to a storefront in the Shopify admin, so select the storefront that you created in Step 1. env pull copies the storefront's environment variables into .env:

Terminal

npx shopify hydrogen link
npx shopify hydrogen env pull

To use an existing private Storefront API token without linking, add your store domain and token to .env instead:

Store connection

.env
PUBLIC_STORE_DOMAIN=your-shop.myshopify.com
PUBLIC_STOREFRONT_ID=<your storefront ID>
PRIVATE_STOREFRONT_API_TOKEN=<your private Storefront API token>

PUBLIC_STOREFRONT_ID is optional. Shopify analytics turn on when it's set. The template gets your shop ID from the Storefront API, so you don't set it for analytics.

Until it finds a private Storefront API token, the React Router template reads demo data from mock.shop instead of your store.

Copy .env.example to .env.local, and set the same store domain, public access token, and shop ID that you entered in Vercel:

Store connection

.env.local
NEXT_PUBLIC_SHOPIFY_STORE_DOMAIN=your-shop.myshopify.com
NEXT_PUBLIC_SHOPIFY_STOREFRONT_ACCESS_TOKEN=<your public Storefront API token>
NEXT_PUBLIC_SHOPIFY_SHOP_ID=<your numeric shop ID>
NEXT_PUBLIC_SHOPIFY_STOREFRONT_ID=<your storefront ID>

The first three variables are required. NEXT_PUBLIC_SHOPIFY_STOREFRONT_ID is optional, and attributes storefront traffic and analytics to your Headless storefront. Find it in the storefront's URL in the Headless channel. It's the number after /headless/. For other settings, refer to Vercel Shop's environment variables.

When you change a variable later, also change it in your Vercel project's Settings > Environment Variables, and then redeploy.

Both templates include customer accounts, but they need extra environment variables and HTTPS (a public tunnel for local Vercel Shop sign-in). On Oxygen, your storefront provides the variables. To learn about setting them up, refer to Set up customer accounts. In Vercel Shop, customer accounts are off by default. To turn them on, refer to Vercel Shop's authentication guide.


Anchor to Step 3: Run your storefrontStep 3: Run your storefront

Start the development server:

Terminal

npm run dev
pnpm dev

Open the local URL that the command prints. The React Router template runs at http://localhost:5173, and Vercel Shop runs at http://localhost:3000.

Your local storefront shows your store's products, like your deployed one. Browse a collection, open a product, choose a variant, and add it to your cart. The cart drawer opens with your item.


Anchor to Step 4: Explore your storefrontStep 4: Explore your storefront

Each template is an ordinary app for its framework. Hydrogen adds three things to it:

  • Request handlers that run before your router, and serve the routes that every Shopify storefront needs, like /api/cart and cart permalinks.
  • A Storefront API client that your pages use to fetch products, collections, and other store data.
  • Cart state that every component that shows the cart shares, and that stays in sync with Shopify.

The following table shows where to find each part in each template:

PartReact RouterVercel Shop
Pagesapp/routes/, registered in app/routes.tsapp/
Request handlersThe middleware export in app/root.tsxproxy.ts
Shopify redirects, which run after your router returns a 404The middleware export in app/root.tsxapp/not-found.tsx, enabled by redirects.shopifyNotFound.isEnabled
Storefront API clientapp/lib/storefront.tslib/shopify/storefront/server.ts
QueriesIn each route's filelib/shopify/operations/
Route templatesapp/lib/route-templates.tslib/shopify/routing/index.ts
Cartapp/lib/cart-handlers.ts, app/lib/cart.ts, and app/components/CartDrawer.tsxlib/cart/server.ts, lib/cart/client.ts, and components/cart/
Store settingsapp/lib/shop.tslib/config/index.ts
Stylesapp/tokens.css and app/app.cssapp/globals.css

In the React Router template, open the home page's file, app/routes/home.tsx, and find the Home query that fetches the products and collections that the page shows. To show more data on the page, add fields to that query. In Vercel Shop, find the queries for each page in lib/shopify/operations/. To learn how queries work, refer to Query the Storefront API.



Was this page helpful?