laravel-frontend-presets / tall

A TALL (Tailwind CSS, Alpine.js, Laravel and Livewire) Preset for Laravel
MIT License
2.46k stars 207 forks source link

Use Tailwind's built-in `purge` #4

Closed mikemand closed 4 years ago

mikemand commented 4 years ago

I don't know if this is something that anyone wants to do because it is incredibly opinionated, but I thought I would PR it anyway.

Tailwind v1.4 has PurgeCSS built-in now, so it's not strictly necessary we use Spatie's package. However, I know Tailwind's implementation does not automatically set up all the directories to scan.

This package will put the burden on the end developer to manage their own directories, but I can foresee an increase in tickets here because "CSS classes are missing".

If there are no objections, I will mark the PR as ready for review so it can be merged. Otherwise, we can close this PR.

mikemand commented 4 years ago

I should note that if you don't opt to go with Tailwind's purge, we need to set purge: false in the config to prevent this warning:

Screen Shot 2020-05-07 at 6 01 02 PM
imliam commented 4 years ago

I like it and am happy for it to be merged 👍 It makes sense to use the built-in tool rather than relying on another dependency that does the same.

Instead of putting it on the end developer to set up their directories, we could implement the sensible defaults from the underlying package we're already using: https://github.com/spatie/postcss-purgecss-laravel/blob/master/src/defaultConfig.js

{
    content: [
        "app/**/*.php",
        "resources/**/*.html",
        "resources/**/*.js",
        "resources/**/*.jsx",
        "resources/**/*.ts",
        "resources/**/*.tsx",
        "resources/**/*.php",
        "resources/**/*.vue",
        "resources/**/*.twig",
    ],
    defaultExtractor: (content) => content.match(/[\w-/.:]+(?<!:)/g) || [],
    whitelistPatterns: [/-active$/, /-enter$/, /-leave-to$/, /show$/],
}

Tailwind's built-in purging only runs when the environment is set to production (ie. you run npm run prod) anyway - so will be fine during development, and behave the same as the preset currently does.

mikemand commented 4 years ago

I agree and I think this is a sensible default. If a developer doesn't need/use something they are free to remove it from this config file after it has been published. Uploading the requested changes now. 👍

mikemand commented 4 years ago

Oh, I also removed my example from the README, since the config file itself is now a pretty extensive example.

danharrin commented 4 years ago

Nice work!

mikemand commented 4 years ago

Hi Dan & Liam,

Thank you! I'm really excited to use this preset for any future TALL stack projects.