1 of 63

Getting Started with Gatsby

A React Love Story

Ryan Harris

Software Engineer @ Guru

@ryan_c_harris

2 of 63

Ivana Veliskova

Mansi Pathak

Ryan Yurkanin

“Confessions of an Impostor”

PhillyXP // Last Week

“Component Tree Visualization in React”

Philadelphia JavaScript Developers // Last Week

“Why React Hooks, and how did we even get here?”

RQ React // Later Tonight

@ryan_c_harris

© 2018 Guru Technologies, Inc.

3 of 63

We are currently hiring.

@ryan_c_harris

© 2018 Guru Technologies, Inc.

4 of 63

We are currently hiring.

@ryan_c_harris

© 2018 Guru Technologies, Inc.

5 of 63

“This guy looks familiar...”

~ Maybe You

@ryan_c_harris

© 2018 Guru Technologies, Inc.

6 of 63

It us.

@ryan_c_harris

© 2018 Guru Technologies, Inc.

7 of 63

It us.

© 2018 Guru Technologies, Inc.

8 of 63

Shut up and get on with the Gatsby stuff already!

~ Definitely You

@ryan_c_harris

© 2018 Guru Technologies, Inc.

9 of 63

You got it!

@ryan_c_harris

© 2018 Guru Technologies, Inc.

10 of 63

What we’re going to talk about today

What Gatsby is (and why use it)

Working with Gatsby

How to deploy your statically generated Gatsby site

@ryan_c_harris

© 2018 Guru Technologies, Inc.

11 of 63

What is Gatsby?

@ryan_c_harris

© 2018 Guru Technologies, Inc.

12 of 63

Definition:

A static site generator takes source files and generates an entirely static website.

@ryan_c_harris

© 2018 Guru Technologies, Inc.

13 of 63

Gatsby & GraphQL

@ryan_c_harris

© 2018 Guru Technologies, Inc.

14 of 63

Why use Gatsby?

@ryan_c_harris

© 2018 Guru Technologies, Inc.

15 of 63

Advantages of using Gatsby

  1. It’s blazing fast!

@ryan_c_harris

© 2018 Guru Technologies, Inc.

16 of 63

Advantages of using Gatsby

  • It’s blazing fast!
  • You can use data from a wide variety of sources

@ryan_c_harris

© 2018 Guru Technologies, Inc.

17 of 63

Advantages of using Gatsby

  • It’s blazing fast!
  • You can use data from a wide variety of sources
    1. Your file system

@ryan_c_harris

© 2018 Guru Technologies, Inc.

18 of 63

Advantages of using Gatsby

  • It’s blazing fast!
  • You can use data from a wide variety of sources
    • Your file system
    • APIs

@ryan_c_harris

© 2018 Guru Technologies, Inc.

19 of 63

Advantages of using Gatsby

  • It’s blazing fast!
  • You can use data from a wide variety of sources
    • Your file system
    • APIs
    • Databases

@ryan_c_harris

© 2018 Guru Technologies, Inc.

20 of 63

Advantages of using Gatsby

  • It’s blazing fast!
  • You can use data from a wide variety of sources
    • Your file system
    • APIs
    • Databases
    • Content management systems

@ryan_c_harris

© 2018 Guru Technologies, Inc.

21 of 63

Advantages of using Gatsby

  • It’s blazing fast!
  • You can use data from a wide variety of sources
    • Your file system
    • APIs
    • Databases
    • Content management systems
  • There are lots of deployment options

@ryan_c_harris

© 2018 Guru Technologies, Inc.

22 of 63

Advantages of using Gatsby

  • It’s blazing fast!
  • You can use data from a wide variety of sources
    • Your file system
    • APIs
    • Databases
    • Content management systems
  • There are lots of deployment options
  • Large community support

@ryan_c_harris

© 2018 Guru Technologies, Inc.

23 of 63

How does React fit in?

@ryan_c_harris

© 2018 Guru Technologies, Inc.

24 of 63

Everything is a component!

@ryan_c_harris

© 2018 Guru Technologies, Inc.

25 of 63

GIF break!

@ryan_c_harris

© 2018 Guru Technologies, Inc.

26 of 63

GIF break!

To talk about plugins and starters.

@ryan_c_harris

© 2018 Guru Technologies, Inc.

27 of 63

Plugins

Additional Gatsby functionality

@ryan_c_harris

© 2018 Guru Technologies, Inc.

28 of 63

Starters

Gatsby site boilerplates

@ryan_c_harris

© 2018 Guru Technologies, Inc.

29 of 63

package.json

@ryan_c_harris

© 2018 Guru Technologies, Inc.

30 of 63

Who is using Gatsby?

@ryan_c_harris

© 2018 Guru Technologies, Inc.

31 of 63

Examples of Gatsby in production

Dan Abramov’s (React team) blog

Ryan Yurkanin (Lead @ Guru) blog

Official React documentation from Facebook

  1. My Website!

Shameless self-promo :-)

@ryan_c_harris

© 2018 Guru Technologies, Inc.

32 of 63

Working with Gatsby

@ryan_c_harris

© 2018 Guru Technologies, Inc.

33 of 63

> npm install -g gatsby-cli

@ryan_c_harris

© 2018 Guru Technologies, Inc.

34 of 63

Gatsby commands

> gatsby new [repo name] [starter repo]

Create a new Gatsby project

> gatsby develop

Start up dev server

> gatsby build

Compile source finals, output files for production

> gatsby serve

Serve files build with gatsby build

@ryan_c_harris

© 2018 Guru Technologies, Inc.

35 of 63

> gatsby new my-blog [repo_url]

Create a new site using the official Gatsby blog starter

@ryan_c_harris

© 2018 Guru Technologies, Inc.

36 of 63

PSA: Remember to npm install

@ryan_c_harris

© 2018 Guru Technologies, Inc.

37 of 63

Gatsby file structure

@ryan_c_harris

© 2018 Guru Technologies, Inc.

38 of 63

Gatsby file structure

All your working files

@ryan_c_harris

© 2018 Guru Technologies, Inc.

39 of 63

Gatsby file structure

All your working files

Build files ready to be deployed to production

@ryan_c_harris

© 2018 Guru Technologies, Inc.

40 of 63

Gatsby file structure

All your working files

Build files ready to be deployed to production

Gatsby plugins & npm packages

@ryan_c_harris

© 2018 Guru Technologies, Inc.

41 of 63

Gatsby file structure

All your working files

Build files ready to be deployed to production

Gatsby plugins & npm packages

Site and plugin configuration

@ryan_c_harris

© 2018 Guru Technologies, Inc.

42 of 63

Gatsby file structure

All your working files

Build files ready to be deployed to production

Gatsby plugins & npm packages

Site and plugin configuration

GraphQL and data configuration

@ryan_c_harris

© 2018 Guru Technologies, Inc.

43 of 63

Gatsby file structure

Gatsby cache files

@ryan_c_harris

© 2018 Guru Technologies, Inc.

44 of 63

Gatsby file structure

Gatsby cache files

* You may need to delete this directory

@ryan_c_harris

© 2018 Guru Technologies, Inc.

45 of 63

Gatsby file structure

Gatsby cache files

* You may need to delete this directory

Included in the .gitignore

@ryan_c_harris

© 2018 Guru Technologies, Inc.

46 of 63

> gatsby develop

Fire up your local development server

@ryan_c_harris

© 2018 Guru Technologies, Inc.

47 of 63

http://localhost:8000

@ryan_c_harris

© 2018 Guru Technologies, Inc.

48 of 63

http://localhost:8000/___graphql

@ryan_c_harris

© 2018 Guru Technologies, Inc.

49 of 63

Let’s live code!

Cause that always goes well.

@ryan_c_harris

© 2018 Guru Technologies, Inc.

50 of 63

Deploying Gatsby

@ryan_c_harris

© 2018 Guru Technologies, Inc.

51 of 63

“I love Daisy... but I hate deploying code!”

@ryan_c_harris

© 2018 Guru Technologies, Inc.

52 of 63

> gatsby build

Run this command to build your

production files

@ryan_c_harris

© 2018 Guru Technologies, Inc.

53 of 63

Places to host your built site

  1. Netlify

@ryan_c_harris

© 2018 Guru Technologies, Inc.

54 of 63

Places to host your built site

  • Netlify
  • GitHub Pages

@ryan_c_harris

© 2018 Guru Technologies, Inc.

55 of 63

Places to host your built site

  • Netlify
  • GitHub Pages
  • Heroku

@ryan_c_harris

© 2018 Guru Technologies, Inc.

56 of 63

Places to host your built site

  • Netlify
  • GitHub Pages
  • Heroku
  • AWS S3

@ryan_c_harris

© 2018 Guru Technologies, Inc.

57 of 63

Places to host your built site

  • Netlify
  • GitHub Pages
  • Heroku
  • AWS S3
  • Now.sh

@ryan_c_harris

© 2018 Guru Technologies, Inc.

58 of 63

Deploy to GitHub Pages

@ryan_c_harris

© 2018 Guru Technologies, Inc.

59 of 63

> npm install gh-pages

This package makes deploying your site to GitHub Pages easier

@ryan_c_harris

© 2018 Guru Technologies, Inc.

60 of 63

@ryan_c_harris

© 2018 Guru Technologies, Inc.

61 of 63

@ryan_c_harris

© 2018 Guru Technologies, Inc.

62 of 63

Thank You

Ryan Harris

@ryan_c_harris

Software Engineer @ Guru

@ryan_c_harris

© 2018 Guru Technologies, Inc.

63 of 63

Questions?

Ryan Harris

@ryan_c_harris

Software Engineer @ Guru

@ryan_c_harris

© 2018 Guru Technologies, Inc.