This package wraps the standalone Tailwind CSS CLI tool. No Node.js required.
This package was inspired by the Tailwind CSS for Rails gem.
You can install the package via composer:
composer require tonysm/tailwindcss-laravelOptionally, you can publish the config file with:
php artisan vendor:publish --tag="tailwindcss-config"The package consists of 4 commands and a helper function.
Since each OS/CPU needs its own version of the compiled binary, the first thing you need to do is run the download command:
php artisan tailwindcss:downloadThis will detect the correct version based on your OS and CPU architecture.
By default, it will place the binary at the root of your app. The binary will be called tailwindcss. You may want to add that line to your project's .gitignore file.
Alternatively, you may configure the location of this binary file in the config/tailwindcss.php (make sure you export the config file if you want to do that).
There are some files needed for the setup to work. On a fresh Laravel application, you may run the install command, like so:
php artisan tailwindcss:installThis will ensure there's a tailwind.config.js file at the root of your project, as well as a resources/css/app.css file with the basic Tailwind CSS setup.
To build the Tailwind CSS styles, you may use the build command:
php artisan tailwindcss:buildBy default, that will read your resources/css/app.css file and generate the compiled CSS file at public/css/app.css.
You may want to generate the final CSS file with a digest on the file name for cache busting reasons (ideal for production). You may do so with the --digest flag:
php artisan tailwindcss:build --digestYou may also want to generate a minified version of the final CSS file (ideal for production). You may do so with the --minify flag:
php artisan tailwindcss:build --minifyThese two flags will make the ideal production combo. Alternatively, you may prefer using a single --prod flag instead, which is essentially the same thing, but shorter:
php artisan tailwindcss:build --prodWhen developing locally, it's handy to run the watch command, which will keep an eye on your local files and run a build again whenever you make a change locally:
php artisan tailwindcss:watchNote: the watch command is not meant to be used in combination with --digest or --minify flags.
To use the compiled asset, you may use the tailwindcss helper function instead of the mix function like so:
- <link rel="stylesheet" href="{{ mix('css/app.css') }}" >
+ <link rel="stylesheet" href="{{ tailwindcss('css/app.css') }}" >That should be all you need.
When deploying the app, make sure you add the ideal build combo to your deploy script:
php artisan tailwindcss:build --prodIf you're running on a "fresh" app (or an isolated environment, like Vapor), and you have added the binary to your .gitignore file, make sure you also add the download command to your deploy script before the build one. In these environments, your deploy script should have these two lines
php artisan tailwindcss:download
php artisan tailwindcss:build --prodcomposer testPlease see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.