Getting Tailwind CSS into Jigsaw

October 23, 2018

This site is powered by the static site generator Jigsaw, and uses the Tailwind CSS utility-first framework.

Getting Tailwind CSS into Jigsaw is pretty easy if you're already familiar with using various CSS processing tools, along with Laravel Mix and webpack. If, like me, you're only just starting to use these tools, hopefully this will help you.


Assuming you've already got a site using Jigsaw, you'll first need to add a few node packages:

yarn add tailwindcss laravel-mix-purgecss postcss-import --dev

The postcss-import package lets you use @import statements in CSS, while the laravel-mix-purgecss package provides a Mix plugin which removes any unused CSS classes to reduce the payload to browsers. Tailwind CSS generates a very large stylesheet to save you having to write it for yourself, but you are likely only going to use a small subset of all that.


As I was just starting fresh with my new site, I simply placed this into source\_assets\css\main.css:

 * This injects Tailwind's base styles, which is a combination of
 * Normalize.css and some additional base styles.
 * You can see the styles here:
 * https://github.com/tailwindcss/tailwindcss/blob/master/css/preflight.css
@import  "tailwindcss/preflight";

 * This injects any component classes registered by plugins.
@import  "tailwindcss/components";

 * Here you would add any of your custom component classes; stuff that you'd
 * want loaded *before* the utilities so that the utilities could still
 * override them.
 * Example:
 * .btn { ... }
 * .form-input { ... }
 * Or if using a preprocessor or `postcss-import`:
 * @import  "components/buttons";
 * @import  "components/forms";

@import  "components/markdown";

 * This injects all of Tailwind's utility classes, generated based on your
 * config file.
@import  "tailwindcss/utilities";

 * Here you would add any custom utilities you need that don't come out of the
 * box with Tailwind.
 * Example :
 * .bg-pattern-graph-paper { ... }
 * .skew-45 { ... }
 * Or if using a preprocessor or `postcss-import`:
 * @import  "utilities/background-patterns";
 * @import  "utilities/skew-transforms";


I also introduced a source/_assets/css/components/markdown.css file to let me style the HTML generated by the markdown I use to write my blog posts.

 * define markdown styling using tailwind utility classes
.markdown h1 {
  @apply  mb-4;

.markdown p {
  @apply  mb-4 leading-normal;


Lastly, I updated the script in webpack.mix.js:

let mix = require('laravel-mix');
let tailwind = require('tailwindcss');
let build = require('./tasks/build.js');

    plugins: [
        build.watch(['source/**/*.md', 'source/**/*.php', 'source/**/*.scss', '!source/**/_tmp/*']),

    processCssUrls: false,
    postCss: [
    .postCss('source/_assets/css/main.css', 'css/main.css')
    .js('source/_assets/js/main.js', 'js')
        folders: ['source'],

Links and references

The Mix/Webpack script was sourced from hellocosmin/jigsaw-tailwindcss