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
/.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.
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.