How to use Tailwind CSS v1.0 with Laravel Mix
Now that Tailwind CSS is approaching version 1.0, I wanted to go ahead and start using it on some projects that will be launching in the next few months. It seems the API is stable, so now seems like as good a time as any to document how to get Tailwind up and running with a new Laravel project.
Install Dependencies
All you need to do is run a few simple commands.
Install Tailwind 1.0 Beta
yarn add -D tailwindcss@next
Install Laravel Mix Tailwind
yarn add -D laravel-mix-tailwind
Generate Tailwind config file
yarn tailwind init
This is where all of your modifications to Tailwind will live. Check the official documentation for specifics on which keys to add/override depending on your needs.
Replace webpack.mix.js
In your webpack.mix.js file, replace it with this snippet to mimic the default behavior in a new Laravel project.
const mix = require('laravel-mix');
require('laravel-mix-tailwind');
/*
|--------------------------------------------------------------------------
| Mix Asset Management
|--------------------------------------------------------------------------
|
| Mix provides a clean, fluent API for defining some Webpack build steps
| for your Laravel application. By default, we are compiling the Sass
| file for the application as well as bundling up all the JS files.
|
*/
mix.js('resources/js/app.js', 'public/js')
.sass('resources/sass/app.scss', 'public/css')
.options({
postCss: [require('tailwindcss')]
});
The above snippet will compile Tailwind using the standard app.scss as the base. Be sure to add your Tailwind directives to the top of that file so the utility classes are injected. You can also still use SASS if that's something you want to take advantage of inside of your custom CSS components.
Running Mix is the same as always.
yarn run watch
// OR
yarn run dev
Updates
If something changes when Tailwind 1.0 is officially released, I'll try to update this article accordingly. Leave a comment or reach out on Twitter if something needs to be updated or modified.