<?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: Didier Catz</title>
    <description>The latest articles on DEV Community by Didier Catz (@didier).</description>
    <link>https://dev.to/didier</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%2F246261%2Fb9a03afb-bfab-47a1-ab6d-4d43c320ae74.png</url>
      <title>DEV Community: Didier Catz</title>
      <link>https://dev.to/didier</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/didier"/>
    <language>en</language>
    <item>
      <title>Getting started with TailwindCSS in seconds.</title>
      <dc:creator>Didier Catz</dc:creator>
      <pubDate>Sun, 29 Dec 2019 19:07:40 +0000</pubDate>
      <link>https://dev.to/didier/getting-started-with-tailwindcss-in-seconds-8p2</link>
      <guid>https://dev.to/didier/getting-started-with-tailwindcss-in-seconds-8p2</guid>
      <description>&lt;p&gt;If you're familiar with Tailwind and just want to get going, &lt;a href="https://dev.to/didiercatz/getting-started-with-tailwindcss-in-seconds-8p2#hey-this-article-was-about-getting-started-in-seconds-and-you-just-made-me-read-a-paraphrased-version-of-the-documentation"&gt;click me&lt;/a&gt;.&lt;/p&gt;

&lt;h1&gt;
  
  
  First, a small introduction...
&lt;/h1&gt;

&lt;p&gt;For anyone out of the loop, &lt;a href="https://tailwindcss.com"&gt;TailwindCSS&lt;/a&gt; is a CSS utility framework that's been picking up some serious steam. It lets you easily create maintainable styles in the form of configurable class utilities.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;h1&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"font-bold text-6xl leading-none tracking-tight pb-4"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Hello world!&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;gets parsed as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight scss"&gt;&lt;code&gt; &lt;span class="nt"&gt;h1&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;font-weight&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;700&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;4rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;line-height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;letter-spacing&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;-0&lt;/span&gt;&lt;span class="mi"&gt;.025em&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;padding-bottom&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Super neat in my opinion. Another nice-to-have is Tailwind's directives such as &lt;em&gt;@apply&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Using &lt;em&gt;@apply&lt;/em&gt;, we can easily create class components. Say you have a design system, and all your buttons have a certain style. Instead of typing&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"bg-blue-600 py-8 px-10 my-8 text-white font-bold"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Click me&lt;span class="nt"&gt;&amp;lt;/button&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;for every single button on your site, you could simply do&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight scss"&gt;&lt;code&gt;&lt;span class="nt"&gt;button&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;@apply&lt;/span&gt; &lt;span class="nt"&gt;bg-blue-600&lt;/span&gt; &lt;span class="nt"&gt;py-8&lt;/span&gt; &lt;span class="nt"&gt;px-10&lt;/span&gt; &lt;span class="nt"&gt;my-8&lt;/span&gt; &lt;span class="nt"&gt;text-white&lt;/span&gt; &lt;span class="nt"&gt;font-bold&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and change global rules accordingly—like vanilla CSS.&lt;/p&gt;

&lt;h1&gt;
  
  
  "Enough introduction, I want to get started!"
&lt;/h1&gt;

&lt;p&gt;Sure! To get started with TailwindCSS write &lt;code&gt;npm i tailwindcss&lt;/code&gt;(or &lt;code&gt;yarn add tailwindcss&lt;/code&gt;) inside your project. Then, add the &lt;em&gt;@tailwind&lt;/em&gt; directives to your CSS.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight scss"&gt;&lt;code&gt;&lt;span class="k"&gt;@tailwind&lt;/span&gt; &lt;span class="nt"&gt;base&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;@tailwind&lt;/span&gt; &lt;span class="nt"&gt;components&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;@tailwind&lt;/span&gt; &lt;span class="nt"&gt;utilities&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, simply process your CSS using &lt;code&gt;npx tailwind build style.css -o output.css&lt;/code&gt; or include Tailwind as a PostCSS plugin. I prefer the latter, as it's easy to integrate with your own tooling.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;plugins&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="c1"&gt;// ...&lt;/span&gt;
    &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;tailwindcss&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;autoprefixer&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="c1"&gt;// ...&lt;/span&gt;
  &lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Controlling bundle size
&lt;/h2&gt;

&lt;p&gt;Now, using the Tailwind CLI/plugin you end up with a bundle size of about 600kb—minified, that is. That's quite a lot. A good way to bundle only the CSS you're using is by configuring &lt;code&gt;purgecss&lt;/code&gt; in your project. &lt;code&gt;purgecss&lt;/code&gt;removes all unused styles—yes, including Tailwind's—from your files.&lt;/p&gt;

&lt;p&gt;Adding Purgecss to your project is a process of quite a few steps by itself, and you're better off reading into how all that works in the &lt;a href="https://tailwindcss.com/docs/controlling-file-size#setting-up-purgecss"&gt;Tailwind docs on bundle size&lt;/a&gt;.&lt;/p&gt;

&lt;h1&gt;
  
  
  'Hey! This article was about getting started in seconds and you just made me read a paraphrased version of the documentation!'
&lt;/h1&gt;

&lt;p&gt;You're completely right. I figured some introduction would be necessary for those who have not heard of TailwindCSS before. But for those who have, or are at least interested to try it after reading this; I've created &lt;a href="https://github.com/didier/tailwindcss-parcel-boilerplate"&gt;a little tool to boilerplate a new Tailwind project&lt;/a&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx tailwindcss-parcel-boilerplate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Simply run the above command and you'll have your own Tailwind project up and running in seconds. It uses &lt;a href="https://parceljs.org"&gt;Parcel&lt;/a&gt; for watching and bundling your files, and uses &lt;a href="https://www.purgecss.com/"&gt;Purgecss&lt;/a&gt; at build time. You won't experience any slowdown while developing this way and still end up with a really small bundle size.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight scala"&gt;&lt;code&gt;&lt;span class="o"&gt;.&lt;/span&gt;
&lt;span class="o"&gt;├──&lt;/span&gt; &lt;span class="n"&gt;src&lt;/span&gt;
&lt;span class="o"&gt;│&lt;/span&gt;   &lt;span class="o"&gt;├──&lt;/span&gt; &lt;span class="n"&gt;assets&lt;/span&gt;
&lt;span class="o"&gt;│&lt;/span&gt;   &lt;span class="o"&gt;│&lt;/span&gt;   &lt;span class="o"&gt;├──&lt;/span&gt; &lt;span class="n"&gt;css&lt;/span&gt;
&lt;span class="o"&gt;│&lt;/span&gt;   &lt;span class="o"&gt;│&lt;/span&gt;   &lt;span class="o"&gt;│&lt;/span&gt;   &lt;span class="o"&gt;└──&lt;/span&gt; &lt;span class="nv"&gt;style&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="py"&gt;css&lt;/span&gt;
&lt;span class="o"&gt;│&lt;/span&gt;   &lt;span class="o"&gt;│&lt;/span&gt;   &lt;span class="o"&gt;└──&lt;/span&gt; &lt;span class="n"&gt;js&lt;/span&gt;
&lt;span class="o"&gt;│&lt;/span&gt;   &lt;span class="o"&gt;│&lt;/span&gt;       &lt;span class="o"&gt;└──&lt;/span&gt; &lt;span class="nv"&gt;index&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="py"&gt;js&lt;/span&gt;
&lt;span class="o"&gt;│&lt;/span&gt;   &lt;span class="o"&gt;└──&lt;/span&gt; &lt;span class="nv"&gt;index&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="py"&gt;html&lt;/span&gt;
&lt;span class="o"&gt;├──&lt;/span&gt; &lt;span class="nv"&gt;package&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="py"&gt;json&lt;/span&gt;
&lt;span class="o"&gt;└──&lt;/span&gt; &lt;span class="nv"&gt;postcss&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="py"&gt;config&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="py"&gt;js&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A Tailwind setup in seconds—as promised.&lt;/p&gt;

&lt;p&gt;Hope you'll find some use out of my tool. If there's anything you'd like to add, please hop on over to the &lt;a href="https://github.com/didier/tailwindcss-parcel-boilerplate"&gt;GitHub repository&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Cheers!&lt;/p&gt;

</description>
      <category>css</category>
      <category>npm</category>
      <category>javascript</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
