• Stars
    star
    254
  • Rank 160,264 (Top 4 %)
  • Language
    PHP
  • License
    MIT License
  • Created almost 3 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

This package wraps up the standalone executable version of the Tailwind CSS framework for a Laravel application.

Tailwind CSS for Laravel

Total Downloads Latest Stable Version License

Introduction

This package wraps the standalone Tailwind CSS CLI tool. No Node.js required.

Inspiration

This package was inspired by the Tailwind CSS for Rails gem.

Installation

You can install the package via composer:

composer require tonysm/tailwindcss-laravel

Optionally, you can publish the config file with:

php artisan vendor:publish --tag="tailwindcss-config"

Usage

The package consists of 4 commands and a helper function.

Download the Tailwind CSS Standalone Binary

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:download

This 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).

Installing the Scaffolding

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:install

This 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.

Building

To build the Tailwind CSS styles, you may use the build command:

php artisan tailwindcss:build

By 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 --digest

You 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 --minify

These 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 --prod

Watching For File Changes

When 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:watch

Note: the watch command is not meant to be used in combination with --digest or --minify flags.

Using the Compiled Asset

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.

Deploying Your App

When deploying the app, make sure you add the ideal build combo to your deploy script:

php artisan tailwindcss:build --prod

If 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 --prod

Mock Manifest When Testing

The tailwindcss() function will throw an exception when the manifest file is missing. However, we don't always need the manifest file when running our tests. You may use the InteractsWithTailwind trait in your main TestCase to disable that exception throwing:

<?php

namespace Tests;

use Exception;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
use Tonysm\TailwindCss\Testing\InteractsWithTailwind;

abstract class TestCase extends BaseTestCase
{
    use CreatesApplication;
    use InteractsWithTailwind;

    protected function setUp(): void
    {
        parent::setUp();

        $this->withoutTailwind();
    }
}

Alternatively, you may also use the trait on specific test cases if you want to, so we can toggle that behavior as you need:

<?php

namespace Tests;

use Exception;
use Tests\TestCase;
use Tonysm\TailwindCss\Testing\InteractsWithTailwind;

class ExampleTest extends TestCase
{
    use InteractsWithTailwind;

    /** @test */
    public function throws_exception_when_manifest_is_missing()
    {
        $this->expectException(Exception::class);

        $this->withoutExceptionHandling()
            ->get(route('login'));

        $this->fail('Expected exception to be thrown, but it did not.');
    }

    /** @test */
    public function can_disable_tailwindcss_exception()
    {
        $this->withoutTailwind()
            ->get(route('login'))
            ->assertOk();
    }
}

Both tests should pass.

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

More Repositories

1

turbo-laravel

This package gives you a set of conventions to make the most out of Hotwire in Laravel.
PHP
673
star
2

rich-text-laravel

Integrates the Trix Editor with Laravel. Inspired by the Action Text gem from Rails.
PHP
309
star
3

importmap-laravel

Use ESM with import maps to manage modern JavaScript in Laravel without transpiling or bundling.
PHP
116
star
4

slackish-laravel

Implementing a chat app in Laravel
PHP
112
star
5

turbo-demo-app

This is a demo application that uses Turbo Laravel.
PHP
56
star
6

local-time-laravel

This is a Laravel port of the local_time gem from Basecamp.
PHP
56
star
7

globalid-laravel

Identify app models with a URI. Inspired by the globalid gem.
PHP
37
star
8

laravel-elasticsearch-2019

PHP
29
star
9

laravel-paratest

PHP
14
star
10

laradock-cli

This is an experimentation app.
PHP
13
star
11

mychat-php

A chat app using Websocket with Ratchet (not using NodeJS)
PHP
12
star
12

dockerforlaravel-k8s-files

Shell
7
star
13

phredis-server

A naive implementation of Redis protocol in PHP with Amphp (async)
PHP
7
star
14

ldap-server-laravel

PHP
5
star
15

turbo-ram

PHP
4
star
16

stimulus-laravel

Use Stimulus in your Laravel app
PHP
4
star
17

fiap-tech-challenge-1-pedidos

TypeScript
4
star
18

laravel-docker-preset

PHP
3
star
19

laravel-eventsourcing

PHP
3
star
20

dockerforlaravel-app

PHP
3
star
21

laravel-inertia-react

PHP
3
star
22

nodejs-multiuser-chat

An example of using NodeJS and SocketIO in a multi-user chat environment..
3
star
23

ibis-docker

Docker wrapper for the themsaid/ibis e-book generator.
Dockerfile
2
star
24

spa-oauth2-laravel

PHP
2
star
25

laravel-queue-async-apps-example

PHP
2
star
26

turbo-ram-android

Kotlin
2
star
27

cake-i18n-example

Exemplo de Internacionalização i18n
PHP
2
star
28

turbo-laravel-test-helpers

This package adds a couple macros and assertion helpers to your application using Turbo Laravel.
PHP
1
star
29

lara-journal-rich-text-demo

PHP
1
star
30

laravel-docker-demo

PHP
1
star
31

rich-text-demo-app

PHP
1
star
32

swagger-laravel-example

PHP
1
star
33

delegated-types-buckets-recordings

PHP
1
star
34

mytwitter-laravel4

MyTwitter, using Laravel, Travis-CI, Pagodabox (for stage) and Flat-UI
PHP
1
star
35

commands-and-domain-events-tickets

PHP
1
star
36

todo-app-angular-laravel4

Todo App using Angular and Laravel4 (as a RESTful API)
Ruby
1
star
37

laravel-bank-ar

An example application of reification
PHP
1
star
38

turbo-laravel-bootstrap-example

CSS
1
star
39

livewire-demos

PHP
1
star