⚠️ This lesson is retired and might contain outdated information.

Setup The Simplest Gatsby Project

Khaled Garbaya
InstructorKhaled Garbaya
Share this video with your friends

Social Share Links

Send Tweet
Published 4 years ago
Updated 2 years ago

Gatsby Project Structure

Inside a Gatsby project you may have some of the folowing folders/files:

|-- /.cache
|-- /plugins
|-- /public
|-- /src
    |-- /pages
    |-- /templates
    |-- html.js
|-- /static
|-- gatsby-config.js
|-- gatsby-node.js
|-- gatsby-ssr.js
|-- gatsby-browser.js

Folders

  • /.cache Automatically generated. This folder is an internal cache created automatically by Gatsby.

  • /plugins This folder hosts any project-specific (“local”) plugins that aren’t published as an npm package.

  • /public Automatically generated. The output of the build process will be exposed inside this folder.

  • /src This directory will contain all of the code related to what you will see on the frontend of your site (what you see in the browser), like your site header, or a page template. “Src” is a convention for “source code”.

  • /pages Components under src/pages become pages automatically with paths based on their filename.

  • /templates Contains templates for programmatically creating pages.

  • html.js For custom configuration of default .cache/default_html.js.

  • /static If you put a file into the static folder, it will not be processed by Webpack. Instead it will be copied into the public folder untouched.

Files

  • gatsby-browser.js: This file is where Gatsby expects to find any usage of the Gatsby browser APIs (if any). These allow customization/extension of default Gatsby settings affecting the browser.

  • gatsby-config.js: This is the main configuration file for a Gatsby site. This is where you can specify information about your site (metadata) like the site title and description, which Gatsby plugins you’d like to include, etc.

  • gatsby-node.js: This file is where Gatsby expects to find any usage of the Gatsby node APIs (if any). These allow customization/extension of default Gatsby settings affecting pieces of the site build process.

  • gatsby-ssr.js: This file is where Gatsby expects to find any usage of the Gatsby server-side rendering APIs (if any). These allow customization of default Gatsby settings affecting server-side rendering.

Most of the folders and files above are optional.

A Gatsby project is mainly an npm project that has gatsby, react and react-dom as npm dependencies.

The equivalent of index.html in a Gatsby project is an index.js file inside the src/pages folder.

Instructor: [0:00] Inside an empty folder, run npm init -y. Now, let's add some dependencies. We need to install Gatsby, React, and ReactDOM. Let's go to our project inside the package.json.

[0:22] Let's change this script to develop and replace this with gatsby develop. Hit save. Let's go back to the terminal and run npm run develop. Now, let's open this URL, and you can see our Gatsby project is running. It's showing us a 404 because there's no pages in here. Let's create this index.js page. Let's go to our project again.

[0:55] Let's create some folders. First, we'll have an src. Inside of that, we'll have pages. Inside of pages, let's create a new file, call it index.js. Here, let's import React from 'react' and export a simple component. Let's save. You can see here we have our home page. That's how you create the simplest Gatsby project.

egghead
egghead
~ 34 seconds ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today