<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Regisnut</title>
    <description>The latest articles on DEV Community by Regisnut (@regisnut).</description>
    <link>https://dev.to/regisnut</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F357145%2F81401a25-4240-4e1f-bca4-892b746e2274.jpeg</url>
      <title>DEV Community: Regisnut</title>
      <link>https://dev.to/regisnut</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/regisnut"/>
    <language>en</language>
    <item>
      <title> Adding Tailwindcss to my Gatsby website</title>
      <dc:creator>Regisnut</dc:creator>
      <pubDate>Tue, 17 Nov 2020 19:02:15 +0000</pubDate>
      <link>https://dev.to/regisnut/adding-tailwindcss-to-my-gatsby-website-125n</link>
      <guid>https://dev.to/regisnut/adding-tailwindcss-to-my-gatsby-website-125n</guid>
      <description>&lt;p&gt;After following a react formation, I've decided to make a Gatsby website using  Contentful content, and for CSS, I've used bootstrap to help me get something good, also helped with framer-motion for animation.&lt;/p&gt;

&lt;p&gt;But now, I want some change and add Tailwind for sure !!&lt;/p&gt;

&lt;p&gt;Let's follow the steps to start your journey with &lt;a href="https://tailwindcss.com/"&gt;tailwindcss&lt;/a&gt;. 🚀&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Install Tailwind&lt;/li&gt;
&lt;li&gt;install gatsby-plugin-postcss&lt;/li&gt;
&lt;li&gt;Custom CSS&lt;/li&gt;
&lt;li&gt;Purging your CSS&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  1) Install Tailwindcss
&lt;/h2&gt;

&lt;p&gt;In your terminal in your Gatsby project, install Tailwind :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Using NPM

npm install tailwindcss --save-dev

# Using Yarn

yarn add tailwindcss --dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  2) Generate a tailwind config file
&lt;/h2&gt;

&lt;p&gt;In your terminal, still in your gatsby project, just run the following :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx tailwindcss init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You will have a new &lt;strong&gt;tailwind.config.js&lt;/strong&gt; file.&lt;/p&gt;

&lt;h2&gt;
  
  
  3) Install the plugin gatsby-plugin-postcss
&lt;/h2&gt;

&lt;p&gt;You will need also to install the Gatsby PostCSS plugin &lt;strong&gt;&lt;em&gt;gatsby-plugin-postcss.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Tailwind is built on PostCSS, that's why weed the plugin.&lt;/p&gt;

&lt;p&gt;To install the plugin, just run the following in your terminal :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Using NPM
npm install --save gatsby-plugin-postcss

# Using Yarn
yarn add gatsby-plugin-postcss

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  4) Include the plugin in your &lt;code&gt;gatsby-config.js&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;We need to configure Gatsby, hence in your gatsby-config.js, just add the plugin as below (see my example):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;module.exports = {
    siteMetadata: {
        title: `Dreaminh, illustrations, aquarelles &amp;amp; letterings`,
        siteUrl: `https://www.dreaminh.com`,
...
    },
    plugins: [
        `gatsby-plugin-react-helmet`,
        `gatsby-plugin-offline`,
        `gatsby-plugin-netlify`,
...
         `gatsby-plugin-postcss`,
    ]
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  5) Configure PostCSS to use Tailwind
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;To configure PostCSS, you need to create an empty &lt;code&gt;postcss.config.js&lt;/code&gt; file in your project's root.&lt;/li&gt;
&lt;li&gt;Add the following content
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const tailwind = require('tailwindcss')

module.exports = () =&amp;gt; ({
    plugins: [tailwind('./tailwind.config.js'),require("autoprefixer")],
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  6) Add CSS File with tailwind directives
&lt;/h2&gt;

&lt;p&gt;We are getting close, we just need to add our tailwind directives in our css.&lt;/p&gt;

&lt;p&gt;Best practise is to create a &lt;strong&gt;global.css&lt;/strong&gt; file such as &lt;strong&gt;&lt;em&gt;src/styles/global.css&lt;/em&gt;&lt;/strong&gt; and add the following :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@tailwind base;
@tailwind components;
@tailwind utilities;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  7) Use of Tailwind
&lt;/h2&gt;

&lt;p&gt;To finalize the installation, we need to import Tailwind in &lt;code&gt;gatsby-browser.js&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import "./src/styles/global.css"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🚀  And that's it! You should now begin to play with Tailwindcss, as basic configuration is done.&lt;/p&gt;

&lt;p&gt;I hope you will accomplish great things with this framework, obviously to go further don't hesitate to check on the official document, especially to build your custom theme. [&lt;a href="https://tailwindcss.com/"&gt;talwindcss documentation&lt;/a&gt;]&lt;/p&gt;

&lt;h2&gt;
  
  
  Tailwind toolbox
&lt;/h2&gt;

&lt;p&gt;Please find the library which can be helpful : &lt;/p&gt;

&lt;p&gt;&lt;a href="https://tailwindcomponents.com/"&gt;https://tailwindcomponents.com/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://mertjf.github.io/tailblocks/"&gt;https://mertjf.github.io/tailblocks/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://tailwind.build/"&gt;https://tailwind.build/&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  You can find me on:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Instagram: &lt;a href="https://instagram.com/regisnut"&gt;https://instagram.com/regisnut&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Twitter: &lt;a href="https://twitter.com/regisnut"&gt;https://twitter.com/regisnut&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Portfolio: &lt;a href="https://regiscode.netlify.app/"&gt;https://regiscode.netlify.app/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;GitHub: &lt;a href="https://github.com/regisnut"&gt;https://github.com/regisnut&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>tailwindcss</category>
    </item>
  </channel>
</rss>
