项目 / Shopify/hydrogen

Shopify/hydrogen

行业推荐
语言 TypeScript标签 hydrogenreactremixshopifynextjs数据更新 2026-11-22 06:48:52 · 仓库 2026-11-21

一段话介绍

Hydrogen(`@shopify/hydrogen`)是 Shopify 提供的无头店面工具包,可在已有的 JavaScript 框架中使用,并附带教编程助手如何接入的 Agent Skills。当前[仓库 README](https://github.com/Shopify/hydrogen)面向 Hydrogen 2026-10 及之后的版本(更早版本在 `2026-04` 分支)。它提供 Storefront API 客户端、购物车与结账相关请求处理、商品和专辑、预测搜索、金额格式、市场、分析和顾客账户等能力。可在项目根目录执行 `npx @shopify/hydrogen@latest setup` 安装;也可使用 React Router 模板部署到 Oxygen,或查看基于 Hydrogen 的 Next.js 示例。商店需具备 Headless channel 的 Storefront API 访问权限。说明见[官方文档](https://shopify.dev/docs/storefronts/hydrogen)和[项目站](https://hydrogen.shopify.dev)。

本站整理,非 GitHub 官方 description。

官方 description(GitHub API 原样)
Shopify commerce primitives in your framework
2,159累计星
452Fork
—峰值日增
0上榜次数
总榜
暂未入榜
日榜
暂未入榜
周榜
暂未入榜
月榜
暂未入榜

官方快照(gh_history.db,2026-11-25):总榜 未进 Top50 · 日榜 未进 Top50 · 周榜未满 7 天基线(官方不生成) · 月榜暂无官方口径;下方四卡为站内趋势聚合(周卡按上榜次数,非官方 7 日增量窗)。

行业与场景

按行业选型 →

电商交易与订单履约

适配系统:交易中台、订单履约系统 · 得分 1.4

内置商品、购物车、订单与支付对象模型,可作为电商交易中台直接改造复用。

更多信息

以下三段按该项目自己的 GitHub README 章节摘录(可合理截断并标明);README 没有对应章节的留空,不编造。

我的用法
安装或使用说明见 https://shopify.dev/docs/storefronts/headless/building-with-the-storefront-api/manage-headless-channels。
特点或设计要点
Hydrogen 内置类型化 Storefront API 客户端、购物车与商品集合处理、预测搜索、多市场与货币格式化、Shop Pay、客户账户及分析同意管理等 Shopify 店面所需功能。
星标走势还差一天的数据,明天就能看到曲线
每天 10:30 记一次星标,连续两天后自动生成曲线
首次发现 — · 最近在榜 2026-10-27 · 语言 TypeScript · 贡献者 —
typescript

GitHub 项目主页介绍

来自 GitHub 仓库 README / 主页介绍正文,原样摘录,共 11,482 字节。

# Hydrogen

Hydrogen (`@shopify/hydrogen`) is Shopify's toolkit for building headless storefronts in the JavaScript framework you already use. It ships with agent skills that teach coding agents how to use it.

[Documentation](https://shopify.dev/docs/storefronts/hydrogen) · [API reference](https://shopify.dev/docs/api/hydrogen/2026-10) · [Changelog](./packages/hydrogen/CHANGELOG.md)

> [!NOTE]
> This README covers Hydrogen 2026-10 or later. Hydrogen 2026-04 and earlier are on the [`2026-04` branch](https://github.com/Shopify/hydrogen/tree/2026-04), with docs in [Legacy Hydrogen](https://shopify.dev/docs/storefronts/headless/legacy). To migrate a storefront, follow [Migrate to the latest version of Hydrogen](https://shopify.dev/docs/storefronts/hydrogen/migrate).

## What's included

- **Storefront API client**: typed `gql()` queries, caching, and typed errors.
- **Request handlers**: the routes a Shopify storefront needs, such as the Storefront API proxy, `/api/cart`, checkout and cart permalinks, URL redirects, and the MCP endpoints for agents.
- **Cart**: server handlers, HTML forms that work before JavaScript loads, and a store that shows line changes before the server responds.
- **Products and collections**: variant selection, collection filters, sorting, and pagination.
- **Predictive search**: a search store with server handlers and form helpers.
- **Money**: formats Shopify `MoneyV2` amounts for the buyer's locale and currency.
- **Markets**: country and language context for Shopify Markets.
- **Analytics**: Shopify storefront analytics with consent handling.
- **Shop Pay**: Shop Pay buttons.
- **Customer accounts**: the Customer Account API client, login and logout handlers, and sessions.

## Get started

You need a Shopify store with Storefront API access from the [Headless channel](https://shopify.dev/docs/storefronts/headless/building-with-the-storefront-api/manage-headless-channels). Until you connect one, the template and the setup skill fall back to [mock.shop](https://mock.shop), a public Storefront API with demo data.

### Deploy a template

**React Router on Oxygen.** Shopify's starter template, [`templates/react-router`](./templates/react-router), deployed to [Oxygen](https://shopify.dev/docs/storefronts/hydrogen/deploy/oxygen) from your Shopify admin.

<a href="https://admin.shopify.com/hydrogen/new?template=react-router"><img alt="Deploy to Oxygen" src=".github/images/deploy-to-oxygen.svg" width="182" height="46"></a>

**Next.js on Vercel.** [Vercel Shop](https://github.com/vercel/shop) is a Next.js storefront built on Hydrogen and maintained by Vercel.

<a href="https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fvercel%2Fshop&project-name=shop&repository-name=shop&demo-title=Vercel+Shop&demo-url=https%3A%2F%2Ftemplate.vercel.shop&stores=%5B%7B%22type%22%3A%22integration%22%2C%22integrationSlug%22%3A%22shopify%22%2C%22productSlug%22%3A%22shopify%22%2C%22protocol%22%3A%22other%22%7D%5D"><img alt="Deploy with Vercel" src="https://vercel.com/button" width="129" height="40"></a>

### Add Hydrogen to your project

From your project's root directory, run:

```bash
npx @shopify/hydrogen@latest setup
```

`setup` installs `@shopify/hydrogen` with your project's package manager, and copies Hydrogen's agent skills into `.claude/skills` (read by Claude Code) and `.agents/skills` (read by Codex, Cursor, and OpenCode), matched to the installed version. In an empty directory, it offers to create a project from the React Router template.

Then ask your coding agent to build the storefront:

```text
Set up my store with Shopify.
```

The agent follows the `hydrogen-setup` skill. It adds a Storefront API client and request handlers, then builds a home page, collection and search pages, a product page, a cart page and cart drawer, an account page, and consent-gated analytics. It runs your typecheck after each step and smoke-tests the storefront at the end.

### After you upgrade Hydrogen

Skills describe the API of the installed version, so sync them after each upgrade:

```bash
npx @shopify/hydrogen skills sync
```

`npx @shopify/hydrogen skills check` exits non-zero when the skills are out of date, so you can run it in CI. See [Keeping skills in sync](./packages/hydrogen/README.md#keeping-skills-in-sync).

## How it works

Hydrogen has a framework-independent core, plus bindings for React and Vue:

| Entry point | Contains |
| --- | --- |
| `@shopify/hydrogen` | The core. It includes the Storefront API client, `gql`, request handlers, route templates, money formatting, analytics, Shop Pay, caching, and the stores for the cart, product form, collections, and predictive search. |
| `@shopify/hydrogen/react` | React components and hooks built on the core, such as `createCartComponents()`, `createProductComponents()`, `ShopifyScripts`, and `ShopPayButton`. |
| `@shopify/hydrogen/vue` | The same components for Vue, with composables in place of hooks. |

The package has three more entry points:

- `@shopify/hydrogen/customer-account`: the Customer Account API client and customer session helpers.
- `@shopify/hydrogen/vite`: a Vite plugin for trusted local HTTPS during development.
- `@shopify/hydrogen/ts-plugin`: a TypeScript plugin that flags unknown fields in `gql()` queries in your editor.

On the server, the request handlers run before your framework's router. `handleShopifyRoutes()` answers the routes that Hydrogen owns and passes every other request to your router. When your router returns a 404, `handleShopifyRedirects()` checks the store's URL redirects.

In the browser, state that changes while a customer is on the page lives in observable stores: the cart, the product form's selected variant, collection filters, and predictive search results. Each store has `getState()` and `subscribe(listener)`, and the listener receives the full state on every change. The React and Vue bindings wrap the stores in hooks and composables. The cart, collection, and predictive search hooks take a selector, so a component updates only when the selected value changes:

```tsx
import { createCartComponents } from "@shopify/hydrogen/react";
import type { cartHandlers } from "./cart-handlers"; // your cart server handlers

export const { CartProvider, useCart } = createCartComponents<typeof cartHandlers>();

function CartCount() {
  const totalQuantity = useCart((cart) => cart.data.totalQuantity);
  return <span>{totalQuantity}</span>;
}
```

Hydrogen emits and handles Shopify's [standard storefront events and actions](https://shopify.dev/docs/api/storefront-events-and-actions), the same ones that Liquid themes use. Apps can integrate with a Hydrogen storefront the same way they integrate with a theme, and the cart store applies `shopify:cart:*` events from any source, including apps and agents that call Standard Actions. Cart changes need Shopify's runtime scripts on the page: render `ShopifyScripts` in React or Vue, or use `renderShopifyScriptTags()` in other frameworks.

## Query the Storefront API

Create a Storefront API client for each request, in server code. `getBuyerIp()` is yours to implement: return the buyer's IP address from a header that your host sets.

```ts
import {
  createShopifyRequestContext,
  createStorefrontClient,
  defineShopifyI18n,
  gql,
} from "@shopify/hydrogen";

const i18n = defineShopifyI18n({ defaultLocale: { country: "US", language: "EN" } });

const storeDomain = process.env.PUBLIC_STORE_DOMAIN;
const privateStorefrontToken = process.env.PRIVATE_STOREFRONT_API_TOKEN;
if (!storeDomain || !privateStorefrontToken) {
  throw new Error("Set PUBLIC_STORE_DOMAIN and PRIVATE_STOREFRONT_API_TOKEN.");
}

const storefront = createStorefrontClient({
  type: "private",
  requestContext: createShopifyRequestContext({
    request,
    i18n,
    buyerIp: getBuyerIp(request.headers),
  }),
  config: { storeDomain, privateStorefrontToken },
});

const { data } = await storefront.graphql(
  gql(`
    query Home {
      products(first: 3) {
        nodes { handle title }
      }
    }
  `),
);
```

`data` is typed from the Storefront API schema that ships with Hydrogen. To check queries in your editor and in CI, see [GraphQL tooling](./packages/hydrogen/README.md#graphql-tooling).

## Frameworks and runtimes

Hydrogen works in any JavaScript framework that renders on the server. Frameworks without a packaged binding use the core directly.

| Framework | Uses | Starter or example |
| --- | --- | --- |
| React Router | `@shopify/hydrogen/react` | [`templates/react-router`](./templates/react-router) (starter) |
| Next.js | `@shopify/hydrogen/react` | [Vercel Shop](https://github.com/vercel/shop) (starter), [`examples/nextjs`](./examples/nextjs) |
| Nuxt | `@shopify/hydrogen/vue` | [`examples/nuxt`](./examples/nuxt) |
| Astro | `@shopify/hydrogen` | [`examples/astro`](./examples/astro) |
| SvelteKit | `@shopify/hydrogen` | [`examples/sveltekit`](./examples/sveltekit) |
| SolidStart | `@shopify/hydrogen` | [`examples/solid-start`](./examples/solid-start) |

The projects in [`examples/`](./examples) test Hydrogen across frameworks. They aren't starters and aren't versioned for reuse.

The core depends on web platform APIs (`fetch`, `Request`, `Response`, and Web Crypto) rather than on a specific runtime. It targets Oxygen, Node.js, Cloudflare Workers, Deno, and other runtimes that provide those APIs, including Vercel's. The template and examples in this repository run on Oxygen and Node.js. See [About deploying Hydrogen storefronts](https://shopify.dev/docs/storefronts/hydrogen/deploy), and before you go live, work through the [production checklist](https://shopify.dev/docs/storefronts/hydrogen/production-checklist).

## Agent skills

`setup` and `skills sync` copy these skills into your project. Each skill covers one part of a storefront:

- **Setup and verification**: `hydrogen-setup`, `hydrogen-smoke-test`
- **Data and requests**: `hydrogen-storefront-client`, `hydrogen-request-handlers`, `hydrogen-routing`, `hydrogen-markets`, `hydrogen-robots-txt`
- **Cart**: `hydrogen-cart-ui`, `hydrogen-cart-drawer`, `hydrogen-cart-metafields`
- **Products, collections, and search**: `hydrogen-variant-form`, `hydrogen-collection-browser`, `hydrogen-predictive-search`, `hydrogen-image`, `hydrogen-money`
- **Checkout, accounts, and analytics**: `hydrogen-shop-pay`, `hydrogen-customer-account`, `hydrogen-analytics`
- **Hosting and local development**: `hydrogen-oxygen`, `hydrogen-local-https`
- **Migration from classic Hydrogen**: `migrate-to-hydrogen-2026-10`

Read them in [`packages/hydrogen/skills`](./packages/hydrogen/skills).

## Versioning

Hydrogen `2026.10.x` uses version `2026-10` of the Storefront API and the Customer Account API. Hydrogen 2026-04 and earlier are also published as `@shopify/hydrogen`, so a caret range such as `^2026.4.0` can resolve to 2026-10. To stay on a version, use a tilde range, such as `~2026.4.0`.

## Packages

| Package | Description |
| --- | --- |
| [`@shopify/hydrogen`](./packages/hydrogen) | The Hydrogen toolkit and its agent skills. |
| [`@shopify/mini-oxygen`](./packages/mini-oxygen) | A local Oxygen runtime and Vite plugin, for developing and previewing storefronts that deploy to Oxygen. |

## Help

Report bugs in [Issues](https://github.com/Shopify/hydrogen/issues/new/choose), and report security vulnerabilities through [Shopify's bug bounty program](https://hackerone.com/shopify).

## License

[MIT](./LICENSE.md)
↑