3.0.43 β€’ Published 4 days ago

@faststore/core v3.0.43

Weekly downloads
-
License
MIT
Repository
github
Last release
4 days ago

Kick off your store with this boilerplate. This starter ships the main FastStore configuration files to get your store up and running blazing-fast. This source code is the base for FastStore projects starter.

πŸš€ Quick start

  1. Install dependencies

    Install dependencies with yarn

    yarn
  2. Start developing

    Navigate into your new site’s directory and start it up.

    yarn dev
  3. Open the source code and start editing!

    Your site is now running at http://localhost:3000!

🧐 What's inside?

A quick look at the top-level files and directories you'll see in a this NextJS project.

./
β”œβ”€β”€ node_modules
β”œβ”€β”€ @generated
β”œβ”€β”€ cms
β”œβ”€β”€ public
β”œβ”€β”€ src
β”œβ”€β”€ test
β”œβ”€β”€ .babelrc.js
β”œβ”€β”€ .editorconfig
β”œβ”€β”€ .prettierignore
β”œβ”€β”€ .prettierrrc
β”œβ”€β”€ .stylelintignore
β”œβ”€β”€ .gitignore
β”œβ”€β”€ .eslintignore
β”œβ”€β”€ CHANGELOG.md
β”œβ”€β”€ codegen.ts
β”œβ”€β”€ cypress
β”œβ”€β”€ cypress.config.ts
β”œβ”€β”€ faststore.config.default.js
β”œβ”€β”€ faststore.config.js
β”œβ”€β”€ index.ts
β”œβ”€β”€ jest.config.js
β”œβ”€β”€ LICENSE
β”œβ”€β”€ lighthouserc.js
β”œβ”€β”€ next-env.d.ts
β”œβ”€β”€ next.config.ts
β”œβ”€β”€ package.json
β”œβ”€β”€ tsconfig.json
β”œβ”€β”€ postcss.config.js
β”œβ”€β”€ postinstall.js
β”œβ”€β”€ pull_request_template.md
β”œβ”€β”€ README.md
β”œβ”€β”€ stylelint.config.js
β”œβ”€β”€ tsconfig.json
β”œβ”€β”€ vtex.env
  1. /node_modules: This directory contains all of the modules of code that your project depends on (npm packages) are automatically installed.

  2. /src: This directory will contain all of the code related to what you will see on the front-end of your site (what you see in the browser) such as your site header or a page template. src is a convention for β€œsource code”.

  3. .gitignore: This file tells git which files it should not track / not maintain a version history for.

  4. .prettierrc: This is a configuration file for Prettier. Prettier is a tool to help keep the formatting of your code consistent.

  5. LICENSE: NextJS is licensed under the MIT license.

  6. package.json: A manifest file for Node.js projects, which includes things like metadata (the project’s name, author, etc). This manifest is how npm knows which packages to install for your project.

  7. tsconfig.json: The configuration file for the typescript compiler. This will statically analyze your code for errors and bugs before releasing them into production

  8. faststore.config.default.js: Configure your e-commerce platform, default sales channel etc.

  9. @generated: Where TypeScript typings are generated for your GraphQL queries. You can use these files for strongly typing your App

  10. cypress: End to End(e2e) tests using Cypress. Most of the scenarios are covered here. Add your custom flows to avoid regressions

  11. cypress.config.ts: Cypress configuration file

  12. lighthouserc.js: Configures Google Lighthouse CI. This is where you can turn on/off lighthouse assertions to be used by Lighthouse CI Bot/hook

  13. pull_request_template.md: Template used when creating your Pull Requests

  14. .prettierignore: Ignore listed files when applying prettier rules

  15. .eslintignore: Ignore listed files when applying eslint rules

πŸ’» Code Structure

All code is inside the src folder. The code is split into folders that implement an MVC-like architecture.

The controller is inside the src/sdk folder. This is where you will find most logic for the application. This folder contains hooks for adding items to cart, making graphql queries, resizing images, etc. If you need to write a custom business logic this is probably the place to put this logic.

The views are written in the src/components folder and are subdivided into domain-specific components. Cart related items are inside the src/components/cart folder. Search and Product related components like facets, product summary, and search results are in their respective folders. Basic building blocks components used in the sections are inside the UI folder. Section components are those components that occupy a whole slice on the webpage and are desirable to be changed by a CMS. Section components are Product Gallery, Product Shelf and Hero and BannerText.

The model, in a website, is where the data fetching occurs. Since this project uses Jamstack, a crucial design decision was made to explicitly split where Static and Dynamic data are fetched. The files inside the src/pages folder use NextJS's File System Route API to declare routes and fetch static data.

To summarize:

  1. src/pages: Routes are declared and static data is fetched.
  2. src/views: Receives static data from src/pages, enriches this data with dynamic attributes, and render section components along with SEO tags.
  3. src/components/sections: Receives necessary data and use domain-specific components (cart/product/search/ui) for rendering a slice on the web page.

Managing SVG Icons

Icons help build web pages by illustrating concepts and improving website navigation. However, using icons can decrease the page's performance. One option to avoid the decrease of the page's performance is to use SVGs from a single SVG file, located in /static/icons.svg, and load them with the ui/Icon component.

In the following steps, learn how to add and use a new SVG icon and avoid decreasing page performance while using an icon.

Adding an SVG icon

  1. In the SVG file, change the svg tag to symbol.
  2. Add an id to the symbol. Remember to use an unique id and do not replicate it.
  3. Remove unnecessary HTML/SVG properties to allow you to style and decrease the final file size, such as fill, stroke-width, width, height, and color.

An example adding Bell icon:

<svg style="display:none">
<symbol id="Bell" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256"><rect width="256" height="256" fill="none"></rect><path d="M56.2,104a71.9,71.9,0,0,1,72.3-72c39.6.3,71.3,33.2,71.3,72.9V112c0,35.8,7.5,56.6,14.1,68a8,8,0,0,1-6.9,12H49a8,8,0,0,1-6.9-12c6.6-11.4,14.1-32.2,14.1-68Z" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"></path><path d="M96,192v8a32,32,0,0,0,64,0v-8" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"></path></symbol>
</svg>

Using an SVG icon

  1. Get the icon's id that you created in the SVG icon file.
  2. Add the id in the React component that you desire to use the SVG icon. For example
// src/components/ui/MyIconButton/MyIconButton.tsx
import Icon from '@faststore/ui'

function ButtonIcon() {
  return (
    <button>
      <Icon name="<<symbol_id>>" weight="thin" />
    </button>
  )
}

export default ButtonIcon

This project uses SVGs from Phosphor icons. More details, please refer to this doc.

πŸ–ŠοΈ Styling Components

Our customized themes are based on Design Tokens using CSS Variables or a CSS class for each token. We utilize the styles from the @faststore/ui package, which are imported into the src/styles directory. Additionally, each component's styles are imported directly into the section where they are being used. Refer to Theming overview for more details.

πŸ’ Adding queries

We use graphql-codegen to pre-process GraphQL queries. This compilation generates TypeScript typings and configurations for our graphql server under the folder @generated/graphql. This means we can statically analyze your code in search of bugs and secure your graphql server before each deploy. If, however you need to change any GraphQL Fragment, Query or Mutation, you will need to regenerate the whole thing. To do this, open your terminal and type

$ yarn dev

Now, after the nextjs development server is up and running, open another terminal and run

$ yarn generate

That's it! you have just regenerated all graphql queries/fragments for your application and the new data you requested should be available to your component.

Pro tip: Pass -w to the yarn generate command so it watches for changes and you don't need to run this command multiple times.

CMS Integration

This store is integrated with VTEX headless CMS.

The page rendered with CMS is the index page: pages/index.tsx The cms/faststore contains the content-types.json and sections.json files.

CMS configs

It's possible to change the CMS tenant and workspace at faststore.config.default.js.

πŸŽ“ Learning the Frameworks

Looking for more guidance? Full documentation for FastStore lives on this GitHub repository. Also, for learning NextJS, take a look at the NextJS Website, they have plenty of tutorials and examples in there.

⚑ Performance & QA

This project has strict performance budgets. Right out of the box, this project performs around 95 on Google's Page Speed Insights website, which usually is way more strict than your laptop's chrome lighthouse. Every time you commit to the repository, our QA bots will run and evaluate your code quality. We recommend you NEVER put in production a code that breaks any of the bots. If a bot breaks and still you need to put the code into production, change the bot config (lighthouserc.js, cypress.config.ts) to make it pass and merge. This way you ensure your website will keep performing well during the years to come.

Adding third party scripts

Adding third-party scripts to a webpage usually makes it slow. To maintain great performance while third-party scripts are added, this project uses Partytown, a lazy-load library that helps relocate intensive scripts into a web worker and off of the main thread.

To add scripts using Partytown, add the type="text/partytown" to the script tag and make sure to add it before the Partytown script or component. Some third-party scripts execute expensive computations that may require some time to run, making pages few slow. If that's the case, wrap those in a function and reference it on the Partytown forward prop. By doing this, Partytown will run this function on a web worker so it doesn't block the main thread.

export const onRenderBody = ({ setHeadComponents }) => {
  // ...
  setHeadComponents([
    <script type="text/partytown">
      window.expensiveFunction = function() {/* expensive computation used by custom-script */}
    </script>
    <script key="custom-script" src="*://domain/path" type="text/partytown" />,
    <Partytown key="partytown" forward={["expensiveFunction"]} />
  ])
  // ...
}

For more information about integrating third-party scripts: Partytown Wiki.

3.0.43

4 days ago

3.0.42

8 days ago

3.0.41

10 days ago

3.0.40

10 days ago

3.0.39

15 days ago

3.0.38

18 days ago

3.0.37

18 days ago

3.0.36

24 days ago

3.0.32-alpha.0

25 days ago

3.0.34

28 days ago

3.0.35

28 days ago

3.0.32

1 month ago

3.0.33

1 month ago

3.0.31

1 month ago

3.0.30

1 month ago

3.0.27

1 month ago

3.0.26

1 month ago

3.0.25

1 month ago

3.0.24

1 month ago

3.0.22

2 months ago

3.0.21

2 months ago

3.0.20

2 months ago

3.0.17

2 months ago

3.0.16

2 months ago

3.0.15

2 months ago

3.0.13

2 months ago

3.0.14

2 months ago

3.0.12

2 months ago

3.0.11

2 months ago

3.0.10

2 months ago

3.0.8

3 months ago

3.0.7

3 months ago

3.0.4

3 months ago

3.0.3

3 months ago

3.0.6

3 months ago

3.0.5

3 months ago

3.0.2

3 months ago

3.0.1

3 months ago

3.0.0

3 months ago

2.2.77

3 months ago

2.2.78

3 months ago

2.2.76

3 months ago

2.2.74

3 months ago

2.2.73

4 months ago

2.2.71

4 months ago

2.2.70

4 months ago

2.2.69

4 months ago

2.2.68

4 months ago

2.2.66

4 months ago

2.2.67

4 months ago

2.2.65

4 months ago

2.2.63

4 months ago

2.2.61

4 months ago

2.2.60

5 months ago

2.2.59

5 months ago

2.2.58

5 months ago

2.2.57

5 months ago

2.2.56

5 months ago

2.2.55

5 months ago

2.2.53

5 months ago

2.2.54

5 months ago

2.2.51

5 months ago

2.2.52

5 months ago

2.2.50

5 months ago

2.2.49

5 months ago

2.2.48

5 months ago

2.2.46

5 months ago

2.2.47

5 months ago

2.2.44

5 months ago

2.2.45

5 months ago

2.2.43

5 months ago

2.2.42

5 months ago

2.2.41

5 months ago

2.1.87

8 months ago

2.1.83

8 months ago

2.1.84

8 months ago

2.1.81

8 months ago

2.1.82

8 months ago

2.1.80

8 months ago

2.2.0-alpha.10

7 months ago

2.2.0-alpha.12

7 months ago

2.2.0-alpha.13

7 months ago

2.1.98

7 months ago

2.1.99

7 months ago

2.1.101

7 months ago

2.1.96

8 months ago

2.1.100

7 months ago

2.1.103

7 months ago

2.1.94

8 months ago

2.1.102

7 months ago

2.1.95

8 months ago

2.1.105

7 months ago

2.1.104

7 months ago

2.1.93

8 months ago

2.1.107

7 months ago

2.1.90

8 months ago

2.1.106

7 months ago

2.1.91

8 months ago

2.2.1

7 months ago

2.2.0

7 months ago

2.2.3

7 months ago

2.2.2

7 months ago

2.2.5

6 months ago

2.2.4

7 months ago

2.2.7

6 months ago

2.2.9

6 months ago

2.2.8

6 months ago

2.1.27

10 months ago

2.1.28

10 months ago

2.1.38

10 months ago

2.1.39

10 months ago

2.1.36

10 months ago

2.1.35

10 months ago

2.1.33

10 months ago

2.1.31

10 months ago

2.2.17

6 months ago

2.1.49

10 months ago

2.2.18

6 months ago

2.2.15

6 months ago

2.2.16

6 months ago

2.1.48

10 months ago

2.2.13

6 months ago

2.2.14

6 months ago

2.2.11

6 months ago

2.1.43

10 months ago

2.2.12

6 months ago

2.2.10

6 months ago

2.1.42

10 months ago

2.1.40

10 months ago

2.2.19

6 months ago

2.2.26

6 months ago

2.1.59

9 months ago

2.2.24

6 months ago

2.1.56

9 months ago

2.1.57

9 months ago

2.2.22

6 months ago

2.1.54

9 months ago

2.2.23

6 months ago

2.1.55

9 months ago

2.2.20

6 months ago

2.2.21

6 months ago

2.1.53

9 months ago

2.1.51

9 months ago

2.1.109

7 months ago

2.2.0-alpha.8

7 months ago

2.2.0-alpha.7

7 months ago

2.2.0-alpha.6

7 months ago

2.2.0-alpha.5

7 months ago

2.2.0-alpha.9

7 months ago

2.2.39

5 months ago

2.2.37

5 months ago

2.1.69

9 months ago

2.2.38

5 months ago

2.2.35

5 months ago

2.1.67

9 months ago

2.2.36

5 months ago

2.1.68

9 months ago

2.2.33

5 months ago

2.2.34

5 months ago

2.1.66

9 months ago

2.2.31

5 months ago

2.2.0-alpha.0

8 months ago

2.2.32

5 months ago

2.1.64

9 months ago

2.1.61

9 months ago

2.2.30

5 months ago

2.2.0-alpha.4

8 months ago

2.2.0-alpha.3

8 months ago

2.2.0-alpha.2

8 months ago

2.2.0-alpha.1

8 months ago

2.1.78

8 months ago

2.1.76

9 months ago

2.1.77

8 months ago

2.1.75

9 months ago

2.2.40

5 months ago

2.1.72

9 months ago

2.1.73

9 months ago

2.1.70

9 months ago

2.1.71

9 months ago

2.1.26

10 months ago

2.1.23

10 months ago

2.1.24

10 months ago

2.1.22

10 months ago

2.0.173-alpha.0

11 months ago

2.0.99-alpha.0

1 year ago

2.0.139-alpha.0

12 months ago

2.0.111-alpha.0

1 year ago

2.0.156-alpha.0

12 months ago

2.0.106-alpha.0

1 year ago

2.0.87-alpha.0

1 year ago

2.0.168-alpha.0

11 months ago

2.0.140-alpha.0

12 months ago

2.0.95-alpha.0

1 year ago

2.0.152-alpha.0

12 months ago

2.0.83-alpha.0

1 year ago

2.0.123-alpha.0

1 year ago

2.0.102-alpha.0

1 year ago

2.0.164-alpha.0

11 months ago

2.1.9

11 months ago

2.0.79-alpha.0

1 year ago

2.1.16

11 months ago

2.1.17

11 months ago

2.1.14

11 months ago

2.1.12

11 months ago

2.1.13

11 months ago

2.1.11

11 months ago

2.0.115-alpha.0

1 year ago

2.0.160-alpha.0

12 months ago

2.0.132-alpha.0

12 months ago

2.0.75-alpha.0

1 year ago

2.0.147-alpha.0

12 months ago

2.0.107-alpha.0

1 year ago

2.0.157-alpha.0

12 months ago

2.0.141-alpha.0

12 months ago

2.1.18

11 months ago

2.0.172-alpha.0

11 months ago

2.1.19

11 months ago

2.0.122-alpha.0

1 year ago

2.0.153-alpha.0

12 months ago

2.0.138-alpha.0

12 months ago

2.0.98-alpha.0

1 year ago

2.0.76-alpha.0

1 year ago

2.0.103-alpha.0

1 year ago

2.0.129-alpha.0

1 year ago

2.0.135-alpha.0

12 months ago

2.0.176-alpha.0

11 months ago

2.0.91-alpha.0

1 year ago

2.0.163-alpha.0

11 months ago

2.0.89-alpha.0

1 year ago

2.0.116-alpha.0

1 year ago

2.0.125-alpha.0

1 year ago

2.0.108-alpha.0

1 year ago

2.0.85-alpha.0

1 year ago

2.0.158-alpha.0

12 months ago

2.0.142-alpha.0

12 months ago

2.0.137-alpha.0

12 months ago

2.0.121-alpha.0

1 year ago

2.0.154-alpha.0

12 months ago

2.0.81-alpha.0

1 year ago

2.0.97-alpha.0

1 year ago

2.0.134-alpha.0

12 months ago

2.0.151-alpha.0

12 months ago

2.0.166-alpha.0

11 months ago

2.0.104-alpha.0

1 year ago

2.0.94-alpha.0

1 year ago

2.0.128-alpha.0

1 year ago

2.0.145-alpha.0

12 months ago

2.0.90-alpha.0

1 year ago

2.0.162-alpha.0

11 months ago

2.0.73-alpha.0

1 year ago

2.0.113-alpha.0

1 year ago

2.0.175-alpha.0

11 months ago

2.0.88-alpha.0

1 year ago

2.0.100-alpha.0

1 year ago

2.0.117-alpha.0

1 year ago

2.0.130-alpha.0

1 year ago

2.0.110-alpha.0

1 year ago

2.0.105-alpha.0

1 year ago

2.0.96-alpha.0

1 year ago

2.1.1

11 months ago

2.1.4

11 months ago

2.1.3

11 months ago

2.1.5

11 months ago

2.1.8

11 months ago

2.0.169-alpha.0

11 months ago

2.0.80-alpha.0

1 year ago

2.0.109-alpha.0

1 year ago

2.1.0

11 months ago

2.0.133-alpha.0

12 months ago

2.0.120-alpha.0

1 year ago

2.0.78-alpha.0

1 year ago

2.0.165-alpha.0

11 months ago

2.0.93-alpha.0

1 year ago

2.0.159-alpha.0

12 months ago

2.0.114-alpha.0

1 year ago

2.0.118-alpha.0

1 year ago

2.0.146-alpha.0

12 months ago

2.0.101-alpha.0

1 year ago

2.0.178-alpha.0

11 months ago

2.0.74-alpha.0

1 year ago

2.0.71-alpha.0

1 year ago

2.0.70-alpha.0

1 year ago

2.0.65-alpha.0

1 year ago

2.0.69-alpha.0

1 year ago

2.0.66-alpha.0

1 year ago

2.0.67-alpha.0

1 year ago

2.0.72-alpha.0

1 year ago

0.3.17

1 year ago

0.3.16

1 year ago

0.3.15

1 year ago

0.3.14

1 year ago

0.3.13

1 year ago

0.3.12

1 year ago

0.3.11

1 year ago

0.3.10

1 year ago

0.3.9

1 year ago

0.3.8

1 year ago

0.3.7

1 year ago

0.3.6

1 year ago

0.3.5

1 year ago

0.3.4

1 year ago

0.3.3

1 year ago

0.3.2

1 year ago

0.3.1

1 year ago

0.3.0

1 year ago

0.2.2

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago

0.0.0

2 years ago

22.42.6

2 years ago