How to setup Tailwind CSS with Parcel Bundler

How to setup Tailwind CSS with Parcel Bundler

Introduction

Hi all, this is Adi. Today, I wanted to share with you my experience of how I set up Tailwind CSS with Parcel Bundler, if this interests you continue reading.

I am a long time fan of Bootstrap since version 2, I have used it on nearly all my projects. Bootstrap 4 introduced many new utility classes that have made my life a little easier and my markup more readable. But lately, I have been hearing so much about the brand new CSS framework named Tailwind CSS. I am quite confident that you might have heard about it as well. So I decided to give it a try, I read through their documentation and it was as though it was made for me (this framework is so generic, it will feel the same for anyone ??).

First I tried it with the hosted version of the framework, it has so much flexibility. Now I wanted to take it a set further and see how I could set it up in my development flow. This is where things proved tricky. Their documentation had instructions for Webpack, Gulp, Laravel Mix and a bunch of other JS tools but not for the one I use Parcel Bundler. It took me a while before I could get Tailwind to work with my existing Parcel setup.

Source Code Here

My Setup

First, let’s add the new dev dependencies to your package.json file, you need parcel-bundler, postcss-modules and tailwindcss. Postcss is a css per-processor which Tailwind is built with.

No alt text provided for this image

Next, create postcss.config.js in your project root file. This is the configuration for Postcss module, this will be used by Parcel during build. Also, if the NODE_ENV is set to production, we use prugecss module to compress and just have the classes we use in our markup, this process drastically reduces the final css file. This config is enough for us to get started. If you want to customize Tailwind refer to this page.

No alt text provided for this image


Usage in Markup

In our html markup file, let’s include css file. You’ll notice that extension is .pcss this indicates Parcel Bundler to process that file with Postcss module. This file extension will be renamed to .css during the build process.

No alt text provided for this image


In your app.pcss file include these three lines, this will include Tailwinds css classes, you can write normal css below these lines, that will also be included in the build output.

No alt text provided for this image


Conclusion

Tailwind has been growing on me, I am just getting used to its paradigm but I can see myself use it on my future work. That’s about it, if you face any issues with this configuration, please comment, I will try to help.

That’s all for now, this has been Adi.
If you need a Freelance Developer with Laravel knowledge you can contact me.

Thanks for reading.

要查看或添加评论,请登录

Adi SK的更多文章

  • My Journey with the Tech Stack ?? at Uzhavarbumi

    My Journey with the Tech Stack ?? at Uzhavarbumi

    Four years ago today, on 1/Jun/2019, I "officially" started a new freelance project. For us developers, the official…

    4 条评论
  • How to load custom JSON files into Laravel's config

    How to load custom JSON files into Laravel's config

    Hi All, this is Adi, again with another Laravel blog post. This time I wanted to share my solution to loading custom…

  • How to setup Specific Subdomain routing in Laravel

    How to setup Specific Subdomain routing in Laravel

    Hi all, this is Adi, again with another Laravel post. In one of my recent projects, I had to set up specific subdomain…

    1 条评论
  • Create custom Laravel Helper Methods

    Create custom Laravel Helper Methods

    Hi All, this is Adi, with another Laravel article. I wanted to take some time to explain what Laravel’s Helper methods…

  • What are Laravel Resource Controllers

    What are Laravel Resource Controllers

    Hi all, this is Adi again for a Laravel post. I recently found a lot of questions on StackOverflow asking what Laravel…

  • SimplestWeb Updated

    SimplestWeb Updated

    Hi All, I have some great news about Simplest Web. I’ve decided it’s time to take my freelance efforts to the next…

  • A recap of 2019

    A recap of 2019

    Hi all, this I Adi. 2019 has been a wonderful year for me, so I just wanted to take a moment to reflect and document…

  • Reusing a Controller method for multiple actions in Laravel

    Reusing a Controller method for multiple actions in Laravel

    Hi All, this is Adi with another Laravel tutorial. This time, I wanted to cover my basic solution to a problem we might…

  • How to setup automatic db backup in Laravel

    How to setup automatic db backup in Laravel

    Hi All, this is Adi again with a Laravel related article. This time in a shorter format.

  • Launching Jobs by LaravelCollections.com

    Launching Jobs by LaravelCollections.com

    Hi All. I wanted to show you a service I have been working on for the past few weeks.

社区洞察

其他会员也浏览了