Top Related Projects
A performant frontend ecommerce starter template with Next.js 14 and Medusa.
Saleor Core: the high performance, composable, headless commerce API.
Hydrogen lets you build faster headless storefronts in less time, on Shopify.
A customizable, open-source ecommerce platform built on WordPress. Build any commerce solution you can imagine.
Quick Overview
Vercel/commerce is a Next.js-based e-commerce template that provides a fully functional, customizable online store solution. It integrates with various headless commerce platforms and offers a modern, performant shopping experience out of the box.
Pros
- Highly customizable and extensible
- Built with modern technologies (Next.js, React, TypeScript)
- Seamless integration with multiple headless commerce platforms
- Excellent performance and SEO optimization
Cons
- Steep learning curve for developers unfamiliar with Next.js or React
- Limited built-in design options, requiring custom styling for unique looks
- Potential complexity in setting up and configuring third-party integrations
Code Examples
- Fetching products using the commerce provider:
import { getProduct, getProductsList } from '@framework/product'
export const getStaticProps = async () => {
const products = await getProductsList()
return {
props: { products },
}
}
- Adding an item to the cart:
import { useAddItem } from '@framework/cart'
const AddToCartButton = ({ productId, variantId }) => {
const addItem = useAddItem()
const handleAddToCart = async () => {
await addItem({
productId,
variantId,
})
}
return <button onClick={handleAddToCart}>Add to Cart</button>
}
- Customizing the theme:
// pages/_app.tsx
import { ManagedUIContext, ThemeProvider } from '@components/ui/context'
import type { AppProps } from 'next/app'
const MyApp = ({ Component, pageProps }: AppProps) => {
return (
<ManagedUIContext>
<ThemeProvider>
<Component {...pageProps} />
</ThemeProvider>
</ManagedUIContext>
)
}
export default MyApp
Getting Started
-
Clone the repository:
git clone https://github.com/vercel/commerce.git
-
Install dependencies:
cd commerce yarn
-
Copy the example environment file:
cp .env.template .env.local
-
Update
.env.local
with your commerce provider's credentials. -
Run the development server:
yarn dev
-
Open
http://localhost:3000
in your browser to see the store.
Competitor Comparisons
A performant frontend ecommerce starter template with Next.js 14 and Medusa.
Pros of nextjs-starter-medusa
- More comprehensive e-commerce features, including order management and shipping
- Built-in admin panel for easier store management
- Modular architecture allowing for easier customization and extension
Cons of nextjs-starter-medusa
- Steeper learning curve due to more complex architecture
- Less focus on performance optimization compared to commerce
- Potentially slower initial setup and deployment process
Code Comparison
nextjs-starter-medusa:
import { MedusaProvider } from "medusa-react"
import { QueryClient } from "react-query"
const queryClient = new QueryClient()
function MyApp({ Component, pageProps }) {
return (
<MedusaProvider
queryClientProviderProps={{ client: queryClient }}
baseUrl="http://localhost:9000"
>
<Component {...pageProps} />
</MedusaProvider>
)
}
commerce:
import { SWRConfig } from 'swr'
export default function App({ Component, pageProps }) {
return (
<SWRConfig
value={{
fetcher: (url) => fetch(url).then((res) => res.json()),
}}
>
<Component {...pageProps} />
</SWRConfig>
)
}
The code comparison shows that nextjs-starter-medusa uses Medusa's custom provider and react-query for state management, while commerce relies on SWR for data fetching and caching. This reflects the more specialized nature of nextjs-starter-medusa for e-commerce applications, compared to the more general-purpose approach of commerce.
Saleor Core: the high performance, composable, headless commerce API.
Pros of Saleor
- More comprehensive e-commerce solution with advanced features like multi-channel sales and complex product configurations
- Highly customizable and extensible through its GraphQL API and plugin system
- Stronger focus on scalability and enterprise-level functionality
Cons of Saleor
- Steeper learning curve due to its more complex architecture
- Requires more setup and configuration compared to Commerce's out-of-the-box approach
- May be overkill for simple e-commerce projects or small businesses
Code Comparison
Saleor (Python):
class Product(ModelWithMetadata):
name = models.CharField(max_length=250)
description = models.TextField(blank=True)
product_type = models.ForeignKey(
ProductType, related_name="products", on_delete=models.CASCADE
)
Commerce (JavaScript):
export type Product = {
id: string
name: string
description: string
slug: string
path: string
images: ProductImage[]
}
Both repositories offer e-commerce solutions, but they cater to different needs. Commerce focuses on simplicity and quick setup, making it ideal for small to medium-sized businesses or developers looking for a straightforward solution. Saleor, on the other hand, provides a more robust and feature-rich platform suitable for larger enterprises or complex e-commerce requirements. The code comparison highlights the difference in complexity, with Saleor's model offering more advanced features and relationships compared to Commerce's simpler type definition.
Hydrogen lets you build faster headless storefronts in less time, on Shopify.
Pros of Hydrogen
- Built specifically for Shopify, offering seamless integration with Shopify's ecosystem
- Utilizes React Server Components for improved performance and SEO
- Provides a more opinionated structure, potentially speeding up development for Shopify stores
Cons of Hydrogen
- Limited to Shopify platform, less flexible for other e-commerce solutions
- Steeper learning curve for developers not familiar with Shopify's ecosystem
- Smaller community and fewer resources compared to more general e-commerce frameworks
Code Comparison
Hydrogen example:
import {
useShopQuery,
flattenConnection,
ProductProviderFragment,
} from '@shopify/hydrogen';
export default function Product() {
const {data} = useShopQuery({query: QUERY});
const products = flattenConnection(data.products);
}
Commerce example:
import { getProduct } from '@lib/api/commerce'
export default function Product({ product }) {
return <div>{product.name}</div>
}
export async function getStaticProps({ params }) {
const product = await getProduct(params.slug)
return { props: { product } }
}
Both repositories aim to simplify e-commerce development, but Hydrogen is tailored for Shopify while Commerce offers a more platform-agnostic approach. Hydrogen leverages Shopify-specific features and React Server Components, while Commerce provides a flexible foundation for various e-commerce platforms.
A customizable, open-source ecommerce platform built on WordPress. Build any commerce solution you can imagine.
Pros of WooCommerce
- Mature and widely adopted e-commerce platform with a large ecosystem of plugins and themes
- Seamless integration with WordPress, leveraging its content management capabilities
- Extensive documentation and community support for troubleshooting and customization
Cons of WooCommerce
- Can be resource-intensive, potentially impacting site performance on shared hosting
- Requires more setup and configuration compared to Commerce's out-of-the-box solution
- Less optimized for modern web technologies and performance optimizations
Code Comparison
WooCommerce (PHP):
add_action('woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10);
add_action('woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10);
Commerce (React):
import { ProductCard } from '@components/product'
export default function ProductGrid({ products }) {
return (
<div className="grid grid-cols-1 gap-6 sm:grid-cols-2 lg:grid-cols-3">
{products.map((product) => (
<ProductCard key={product.id} product={product} />
))}
</div>
)
}
The code snippets highlight the different approaches: WooCommerce uses WordPress hooks and PHP, while Commerce employs modern React components and JavaScript for a more streamlined, performance-oriented development experience.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Next.js Commerce
A high-perfomance, server-rendered Next.js App Router ecommerce application.
This template uses React Server Components, Server Actions, Suspense
, useOptimistic
, and more.
Note: Looking for Next.js Commerce v1? View the code, demo, and release notes.
Providers
Vercel will only be actively maintaining a Shopify version as outlined in our vision and strategy for Next.js Commerce.
Vercel is happy to partner and work with any commerce provider to help them get a similar template up and running and listed below. Alternative providers should be able to fork this repository and swap out the lib/shopify
file with their own implementation while leaving the rest of the template mostly unchanged.
- Shopify (this repository)
- BigCommerce (Demo)
- Ecwid by Lightspeed (Demo)
- Medusa (Demo)
- Saleor (Demo)
- Shopware (Demo)
- Swell (Demo)
- Umbraco (Demo)
- Wix (Demo)
Note: Providers, if you are looking to use similar products for your demo, you can download these assets.
Integrations
Integrations enable upgraded or additional functionality for Next.js Commerce
-
- Upgrades search to include typeahead with dynamic re-rendering, vector-based similarity search, and JS-based configuration.
- Search runs entirely in the browser for smaller catalogs or on a CDN for larger.
-
- Edit pages, product details, and footer content visually using React Bricks visual headless CMS.
Running locally
You will need to use the environment variables defined in .env.example
to run Next.js Commerce. It's recommended you use Vercel Environment Variables for this, but a .env
file is all that is necessary.
Note: You should not commit your
.env
file or it will expose secrets that will allow others to control your Shopify store.
- Install Vercel CLI:
npm i -g vercel
- Link local instance with Vercel and GitHub accounts (creates
.vercel
directory):vercel link
- Download your environment variables:
vercel env pull
pnpm install
pnpm dev
Your app should now be running on localhost:3000.
Expand if you work at Vercel and want to run locally and / or contribute
- Run
vc link
. - Select the
Vercel Solutions
scope. - Connect to the existing
commerce-shopify
project. - Run
vc env pull
to get environment variables. - Run
pnpm dev
to ensure everything is working correctly.
Vercel, Next.js Commerce, and Shopify Integration Guide
You can use this comprehensive integration guide with step-by-step instructions on how to configure Shopify as a headless CMS using Next.js Commerce as your headless Shopify storefront on Vercel.
Top Related Projects
A performant frontend ecommerce starter template with Next.js 14 and Medusa.
Saleor Core: the high performance, composable, headless commerce API.
Hydrogen lets you build faster headless storefronts in less time, on Shopify.
A customizable, open-source ecommerce platform built on WordPress. Build any commerce solution you can imagine.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot