22sook00 / sookDev

first try posting blog with Gatsby
sook-dev.vercel.app
BSD Zero Clause License
0 stars 0 forks source link
blog frontend gatsby graphql tailwindcss

😈 Sook Blog with Gatsby

Created blog based on [ {πŸ’Ž : react} , { πŸ’  : Typescript} , {πŸŒͺ : tailwind css} ]

Basic Install


/* step 1_install gatsby cli */
npm install -g gatsby-cli

/* step 2_Create gatsby project name on terminal */
gatsby new projectName

//! if you install gatsby without cli , use below code
npx gatsby-cli new projectName

Typescript Install ( optional )

/* step 3_Install typescript  */
yarn add typescript --dev
yarn add gatsby-plugin-typescript

//! if you apply typescript on your project, please follow below steps

/* step 4_Create tsconfig.json */
yarn tsc --init

/* step 5_Modify gatsby-config.js */
module.exports = {
  siteMetadata: {
    title: `Gatsby Default Starter`,
    description: `Kick off your next, great Gatsby project with this default starter. This barebones starter ships with the main Gatsby configuration files you might need.`,
    author: `@gatsbyjs`,
    siteUrl: `https://gatsbystarterdefaultsource.gatsbyjs.io/`,
  },
  plugins: [
    `gatsby-plugin-typescript`, // -> that has been added!
    `gatsby-plugin-react-helmet`,
    `gatsby-plugin-image`,
    {
      resolve: `gatsby-source-filesystem`,
      options: {
        name: `contents`,
        path: `${__dirname}/contents`,
    },
    `gatsby-transformer-sharp`,
    `gatsby-plugin-sharp`,
    {
      options: {
        name: `gatsby-starter-default`,
        short_name: `starter`,
        start_url: `/`,
        background_color: `#663399`,
        theme_color: `#663399`,
        display: `minimal-ui`,
        icon: `src/images/gatsby-icon.png`,
      },
    },
    `gatsby-plugin-gatsby-cloud`,
  ],
}

/* step 6_Modify gatsby-node.js */
const path = require('path');

// Setup Import Alias
exports.onCreateWebpackConfig = ({ getConfig, actions }) => {
  const output = getConfig().output || {};

  actions.setWebpackConfig({
    output,
    resolve: {
      alias: {
        components: path.resolve(__dirname, 'src/components'),
        utils: path.resolve(__dirname, 'src/utils'),
        hooks: path.resolve(__dirname, 'src/hooks'),
        //! if you wan to import file like
        // import Test from "@src/components/Test";
        '@src': path.resolve(__dirname, 'src'),
      },
    },
  });
};

Tailwindcss Install ( optional )

/* step 7_Install both tailwind and postcss and it makes tailwind.config.js & postcss.config.js automatically */
npm install -D tailwindcss postcss autoprefixer gatsby-plugin-postcss

npx tailwindcss init -p

/* step 8_Apply postcss on gatsby-config */
module.exports = {
  plugins: [
    'gatsby-plugin-postcss',
    // ...
  ],
}

/* step 9_Apply routes on tailwind.config.js */
module.exports = {
  content: [
    "./src/**/*.{js,jsx,ts,tsx}",
  ],

/* step 10_Create global.css and put below code in */
route : './src/styles/global.css'

@tailwind base;
@tailwind components;
@tailwind utilities;

/* step 11_Apply global css which has put tailwind codes in on gatsby-browser.js */
import './src/styles/global.css'
And now you can open your project typing only "gatsby develop" πŸ™ŒπŸΌ

Directory

contents

λΈ”λ‘œκ·Έ 포슀트 κ΄€λ ¨ νŒŒμΌλ“€μ„ μ €μž₯ν•˜κΈ° μœ„ν•œ 디렉토리.

src

- components
- pages

νŽ˜μ΄μ§€μ˜ 역할을 ν•˜λŠ” μ»΄ν¬λ„ŒνŠΈλ₯Ό μ €μž₯ν•˜κΈ° μœ„ν•œ 디렉토리. 기본적으둜 λΈŒλΌμš°μ €μ—μ„œ pages 디렉토리에 μžˆλŠ” 파일의 이름을 톡해 νŽ˜μ΄μ§€μ— μ ‘κ·Όν•  수 있기 λ•Œλ¬Έμ— νŽ˜μ΄μ§€μ˜ 역할이 μ•„λ‹Œ μ»΄ν¬λ„ŒνŠΈλ“€μ€ ν•΄λ‹Ή 디렉토리에 μ €μž₯ν•˜μ§€ μ•ŠλŠ”λ‹€. λ˜ν•œ, νŽ˜μ΄μ§€μ˜ ν…œν”Œλ¦Ώ νŒŒμΌμ—μ„œλ§Œ Query μ •μ˜κ°€ κ°€λŠ₯ν•˜λ‹€. 일반적인 μ»΄ν¬λ„ŒνŠΈμ—μ„œλŠ” λ³€μˆ˜λ‘œμ„œ μ •μ˜κ°€ λΆˆκ°€λŠ₯ν•˜κ³ , StaticQueryλΌλŠ” κΈ°λŠ₯을 톡해 μ •μ˜κ°€λŠ₯.

- hooks

Custom Hooks을 μ €μž₯ν•˜κΈ° μœ„ν•œ 디렉토리.

- templates

κ²Œμ‹œκΈ€ νŽ˜μ΄μ§€μ™€ 같이 νŽ˜μ΄μ§€μ˜ 역할을 ν•˜λ©΄μ„œ 같은 ν˜•μ‹μ˜ μ—¬λŸ¬ μ½˜ν…μΈ λ₯Ό λ³΄μ—¬μ£ΌλŠ” μ»΄ν¬λ„ŒνŠΈλ₯Ό μ €μž₯ν•˜κΈ° μœ„ν•œ 디렉토리.

Gatsbyμ—μ„œ μ œκ³΅ν•˜λŠ” APIλ₯Ό 톡해 이 디렉토리에 μ €μž₯된 ν…œν”Œλ¦Ώ μ»΄ν¬λ„ŒνŠΈλ‘œ μ—¬λŸ¬ νŽ˜μ΄μ§€λ₯Ό λ§Œλ“ λ‹€.

pages λ””λ ‰ν† λ¦¬μ™€λŠ” λ‹€λ₯΄κ²Œ 파일λͺ…μœΌλ‘œ νŽ˜μ΄μ§€μ— 접근이 λΆˆκ°€ν•˜λ‹€.