⚠️ This lesson is retired and might contain outdated information.

Using a Gatsby Plugin

Khaled Garbaya
InstructorKhaled Garbaya

Share this video with your friends

Send Tweet
Published 4 years ago
Updated 2 years ago

A Gatsby plugin is a Node package that uses the Gatsby APIs under the hood.

You can use a plugin to source data into your site, transform content or enhance the output of your site like adding google analytics etc...

Gatsby plugins can be categorized into 3 types:

  • A Gatsby Source plugin (e.g: gatsby-source-contentful pulls data from Contentful)
  • A Gatsby Transformer Plugin (e.g: gatsby-transformer-remark convert markdown text to html)
  • A Gatsby Plugin (e.g: gatsby-plugin-google-analytics adds Google analytics in your site)

How to install and configure a plugin

  1. Install a plugin you can run the command npm install plugin-name e.g npm install gatsby-plugin-postcss.

  2. Add the plugin to your gatsby-config.js file

In this lesson, you learn how to use gatsby-plugin-postcss to add tailwindcss support to your project

Instructor: [0:00] First, let's install tailwindcss as a dev dependency. After that, we need to install the gatsby-plugin-postcss. Let's go to our project and create a gatsby-config.js. In there, let's add our new plugin. Next, let's create a postcss.config.js file and add tailwind as a plugin.

[0:40] Finally, inside of src, let's create a CSS folder. Inside of that, let's create an index.css file. Let's add the tailwind base. Let's go to our components inside the flyout. Since this is used in every page, we can import our CSS in here.

[0:58] Here we will simply import the index.css file. Let's hit Save and run our server. You can see here, the CSS has changed and this is using tailwind.