Creating a Hydrogen front end
npm create @shopify/hydrogen@latest -- --install-deps --mock-shop --path web --language ts --shortcut h2 --styling tailwindThe command above sets a number of defaults such as TypeScript, Tailwind and the directory of the project.
Follow the prompts:
- When prompted, choose "Set up later" for any additional routing options
You should now have two separate directories, one for your Sanity Studio, the other for your Hydrogen app.
./├── /studio # Sanity Studio└── /web # Hydrogen front-endThis 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 web/.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 web folder, run the application in development and open http://localhost:3000 in your browser.
# in /webnpm 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!