Git Product home page Git Product logo

anouarbenhriz / react-storefront Goto Github PK

View Code? Open in Web Editor NEW

This project forked from saleor/storefront

0.0 0.0 0.0 3.14 MB

An open-source storefront in React.js with Next.js. Built for Headless Commerce, using a modern stack with TypeScript, GraphQL, Apollo, and Tailwind CSS.

Home Page: https://reactstorefront.vercel.app

License: Other

TypeScript 99.72% JavaScript 0.18% CSS 0.08% Shell 0.02%

react-storefront's Introduction

Deploy to Vercel

React Storefront

alt text

Live demo / Explore and run the code in CodeSandbox

React Storefront is an open-source frontend e-commerce platform from the Saleor team.

  • Next.js
  • TypeScript
  • GraphQL with Apollo Client
  • Tailwind CSS

Motivation

modern & fast: Project is focusing on best practices for e-commerce, like: SSR & ISR, image optimization.

easily customizable: TailwindCSS can be easily extended and tweaked, or completely changed to your favorite css solution.

works out-of-the-box: Pre configured tools for DX.

Setup

Please note: this project use the pnpm package manager. To install it, run:

npm install -g pnpm

Install dependencies:

pnpm i

Start the dev server:

npm run dev

Storefront can be now accessed at http://localhost:3001/.

Development

Configuration

The .env file contains environment variables used by the application. You can override them by creating .env.local file.

Read more

GraphQL queries

Graphql queries are located under the ./graphql. We strongly encourage use of fragments, which minimizes code duplication and plays nicely with the TypeScript, during transformation of incoming data.

Our client of choice is Apollo, which provides excellent cache and features out of the box. To get fully typed requests and responses, GraphQL Code Generator transforms all .graphql files into ready to use hooks. Generated code is located at ./saleor/api.tsx file.

API endpoint can be configured via .env file.

Workflow

  • Modify or create GraphQL file. For example, new query at ./graphql/queries/FeaturedProducts.graphql
  • Run npm run generate command
  • New query will be added to the ./saleor/api.tsx file
  • Import generated hook (import { useFeaturedProductsQuery } from "@/saleor/api";) in your component code

Script will start the GraphQL Code Generator in the watch mode, so changes in the queries will be automatically updated.

React and Next.js code structure

When creating new components, please follow the React TypeScript Cheatsheet.

Code for the payment gateways can be found at ./components/checkout/payments. At the moment we support Saleor test gateway and basic flow for Stripe.

Routing and urls

Project use file based routing. Available routes can be found at ./pages. Dynamic routes (for example ./pages/product/[slug].tsx) are generated at build time based on getStaticPaths.

To ensure, that Link components use only the existing URLs with required arguments, we use pathpida. It is used to automatically generate the ./lib/$path.ts file with all available routes. File should not be updated manually, instead run:

npm run paths

Since routes require additional arguments with current locale and channel, you should use usePaths hook which will automatically add those. Let's create example component with link to the product page:

import Link from "next/link";
import { usePaths } from "@/lib/paths";

export const ProductLinkComponent = () => {
  const paths = usePaths();
  return (
    <Link href={paths.products._slug(line?.variant?.product?.slug).$url()}>
      <a>Product link</a>
    </Link>
  );
};

Code style

Before commiting the code, make sure to run code linters and formatters:

npm run lint

Other tools

Debugging using VS Code

The repository contains ready to use VS Code debugger configuration (.vscode/launch.json).

Start server in debug mode

npm run debug

Add breakpoints, and start debugging session in your editor.

VS Code GraphQL Extension

GraphQL extension for VSCode adds syntax highlighting, validation, and language features like go to definition, hover information and autocompletion for graphql projects. This extension also works with queries annotated with gql tag.

VS Marketplace link

Bundle metrics

If you want to check how your changes impact page size, use command:

npm run analyze-build

After the build, report will open in your browser.

Deployment

Vercel & Netlify

This application is optimized for deployments on Vercel and Netlify. You can use the following deploy buttons

Deploy to Vercel

Deploy to Netlify

or, configure it directly in the respective cloud provider.

Heroku

For Heroku, you need to specify a LTS version of Node.js in your package.json explicitly. Add the following snippet in package.json:

"engines": {
  "node": ">=14 <17",
  "npm": ">=6.11.0 <8"
}

We don't add this in this codebase as we prefer to target the latest Node.js version.

react-storefront's People

Contributors

krzysztofwolski avatar zaiste avatar irgenkini avatar jwm0 avatar bmigirl avatar adrian-potepa avatar culy247 avatar mirekm avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.