Gatsby Getting Started
by John Vincent
Posted on October 2, 2019
Let's get started with Gatsby.
Gatsby
Gatsby is a huge topic, so let's start with some useful links.
Useful Gatsby Links
Querying data in components with the useStaticQuery hook
gatsby-plugin-styled-components
babel-plugin-styled-components
Debugging the Gatsby process
Useful
Start a Gatsby Project
cd repo-gatsby
mkdir t2
cd t2
npx gatsby new gatsby-blog
To run
cd gatsby-blog
npm run develop
From a browser
http://localhost:8000/
GraphQL
View GraphiQL, an in-browser IDE, to explore your site's data and schema.
http://localhost:8000/___graphql
Enter
query MyQuery {
allSitePage {
nodes {
path
componentPath
}
}
}
Deploy to Netlify
git remote add origin git@github.com:johnvincentio/new-gatsby-blog.git
git push origin master
Create github repo new-gatsby-blog
git@github.com:johnvincentio/new-gatsby-blog.git
- New Site from Git * Github
Only Selected repositories
- new-gatsby-blog
- install
If deploy fails, try clear cache and try again.
Browser
https://bad-housetail-ce3d42.netlify.com/
Gatsby Visual Studio Code Workspace
npm install --save-dev eslint-config-airbnb eslint-plugin-import eslint-plugin-jsx-a11y eslint-plugin-react
.eslintrc.json
{
"extends": ["airbnb"],
"env": {
"browser": true,
"es6": true
},
"parser": "babel-eslint",
"globals": {},
"rules": {
"no-console": 0,
"max-len": [
"error",
{
"code": 120,
"tabWidth": 2,
"comments": 120,
"ignoreTrailingComments": true,
"ignoreUrls": true,
"ignorePattern": "^import\\s.+\\sfrom\\s.+;$"
}
],
"indent": [2, "tab", { "SwitchCase": 1 }],
"no-tabs": 0,
"react/jsx-indent": [2, "tab"],
"react/jsx-indent-props": [2, "tab"],
"jsx-a11y/anchor-is-valid": [
"error",
{
"components": ["Link"],
"specialLink": ["to"]
}
],
"react/destructuring-assignment": ["off", "always"]
},
"plugins": []
}
.eslintignore
node_modules
.prettierignore
.cache
package.json
package-lock.json
public
node_modules
*.md
project.todo
.prettierrc
{
"singleQuote": true
}
cd repo-gatsby/t2/gatsby-blog
mkdir .vscode
.vscode/settings.json
{
"editor.formatOnSave": true
}
Open Workspace
Now open Visual Studio Code for repo-gatsby/t2/gatsby-blog
Change the .js
files to .jsx
.
Open index.jsx
and save. The file should have been reformatted according to AirBnb
rules.
package.json
npm i --save-dev rimraf
Replace scripts
section with
"scripts": {
"start": "npm run develop",
"clean": "rimraf .cache public",
"build": "npm run clean && gatsby build",
"develop": "npm run clean && gatsby develop",
"format": "prettier --write \"**/*.{js,jsx,json,md}\"",
"serve": "gatsby serve",
"spelling": "./md-spell-checker",
"debugger": "node --inspect-brk --no-lazy node_modules/gatsby/dist/bin/gatsby develop",
"test": "echo \"Write tests! -> https://gatsby.dev/unit-testing \""
},
Development Build
npm start
will run the Gatsby development system.
Notice that both development and production builds first remove .cache
. I have found this to be wise as .cache
can create some real problems.
Production Build
npm run build
Run production server
npm run serve
Browser
http://localhost:9000
Gatsby Styled Components
npm i gatsby-plugin-styled-components styled-components babel-plugin-styled-components --save
Gatsby
React
- Basic React
- Basic React Patterns
- Basic React Redux
- Basic React Redux App
- Basic React Testing with Jest and Enzyme
- Building and deploying MyTunes to johnvincent.io
- Building and deploying React Github Helper App to johnvincent.io
- Deploy React App to Heroku using Travis Continuous Integration
- Deploy TaskMuncher React App to AWS
- First time deploy TaskMuncher React App to Digital Ocean
- Gatsby and Client Only Components
- Gatsby Getting Started
- Gatsby React Icons
- Mac Visual Studio Code
- Material-UI
- Material-UI Pickers
- Material-UI Styling
- Optimizing TaskMuncher with Webpack 4
- Overview of React Gomoku
- Overview of React Hangman
- Overview of React Lights Out
- Overview of React Yahtzee
- React Material-UI
- React Production Issues
- React PropTypes
- React/Redux Node/Express Ecosystem
- Redux Dev Tools
- Responsive Material-UI
- Styling Material-UI components using Styled-Components
- TaskMuncher Performance
- Transforming Html with Webpack
- Update TaskMuncher for Lighthouse Findings
- Update TaskMuncher to be a Progressive Web App
- Update TaskMuncher to use React BrowserRouter
- Update TaskMuncher to Webpack v4, Babel v7, Material-UI v3
- Upgrading Babel and ESLint to use React Advanced Language Features
- Webpack Bundle Analyzer