Creating a Hydrogen front end
npm create @shopify/hydrogen@latest -- --install-deps --mock-shop --path sanity-and-hydrogen --language ts --shortcut h2
The command above sets a number of defaults such as TypeScript, Tailwind and the directory of the project.
Follow the prompts:
- Select your styling library (we use Tailwind in this guide)
- When prompted, choose "No, set up later" for the route scaffolding option
You should now have two separate directories, one for your Sanity Studio, the other for your Hydrogen app.
./├── /sanity-and-shopify└── /sanity-and-hydrogen
This will be important later when we begin generating Types from the Studio for Hydrogen.
For your development store you'll need to install the Headless Shopify app to connect your front end to Shopify.
h2 link
– but development stores don't currently support this. We highly recommend switching to a paid plan to test Oxygen deployments if that's the final destination of the experience, as it's easier to troubleshoot deploy issues as you build!The sanity-and-hydrogen/.env
file in your project will need to be updated with your Shopify URL and access tokens from the Headless sales channel.
Once installed, click the "Manage" button next to Storefront API, copy your access tokens and insert them into the .env
file your project.
.env
file to look something like the below# Found in Storefront API section of the Headless App in Shopify AdminPUBLIC_STOREFRONT_API_TOKEN="..."PRIVATE_STOREFRONT_API_TOKEN="shpat_..."# Found in your Shopify dashboardPUBLIC_STORE_DOMAIN="<your-domain>.myshopify.com"PUBLIC_CHECKOUT_DOMAIN="<your-domain>.myshopify.com"# Any random string, but it must be kept secretSESSION_SECRET="..."
Now, enter the sanity-and-hydrogen
folder, run the application in development and open http://localhost:3000 in your browser.
npm run dev
.env
file correctly.You should see a page like the one below with instructions on setting up a route.
Hydrogen is now connected to Shopify and data-ready!