LoginSignup
1
2

More than 3 years have passed since last update.

Gatsby の使い方

Last updated at Posted at 2019-05-01

Gatsby のインストールから起動までです。
次のページとほぼ同じです。
Quick Start

1) インストール
私は、Arch Linux を使っているので次のようにしました。

yay nodejs-gatsby-cli

インストールが完了したらバージョンの確認

$ gatsby --version
2.5.9

2) 新しいサイトの構築

gatsby new gatsby-site

3) 作業フォルダーの変更

cd gatsby-site

4) サーバーの起動
VPS で起動したので、外部からアクセスするようにします。

gatsby develop -H 0.0.0.0

5) http://hostname:8000 にアクセス
gatsby_may0101.png

6) http://hostname:8000/___graphql にアクセス
gatsby_may0102.png

7) src/pages/index.js を改造してみます。

src/pages/index.js
import React from "react"
import { Link } from "gatsby"

import Layout from "../components/layout"
import Image from "../components/image"
import SEO from "../components/seo"

const IndexPage = () => (
  <Layout>
    <SEO title="ホーム" keywords={[`gatsby`, `application`, `react`]} />
    <h1>皆さん こんにちは</h1>
    <p>新しいガッツビイのサイトへようこそ</p>
    <p>さて何かすばらしいものを作りましょう</p>
    <div style={{ maxWidth: `300px`, marginBottom: `1.45rem` }}>
      <Image />
    </div>
    <Link to="/page-2/">Go to page 2</Link>
  </Layout>
)

export default IndexPage

ブラウザーでアクセスして変更が反映されることを確認します。
gatsby_may0401.png

8) 本番用のビルド

gatsby build

9) 本番用のサーバーの起動

gatsby serve -H 0.0.0.0

10) ブラウザーで、http://hostname:9000 にアクセス

ポートが 9000 になります。

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2