spatie / laravel-mix-purgecss

Zero-config Purgecss for Laravel Mix
https://spatie.be/en/opensource
MIT License
874 stars 38 forks source link

Can I recompile assets on template change (purge always enabled)? #88

Closed xorock closed 4 years ago

xorock commented 4 years ago

Let's say I have a simple configuration (purgecss is always enabled)

mix.js('resources/js/app.js', 'public/js')
    .postCss('resources/css/app.css', 'public/css')
    .options({
        postCss: [
            require('postcss-import'),
            require('precss'),
            require('tailwindcss'),
        ],
    })
    .purgeCss({
        enabled: true,
    });

and some blade template

<p class="py-4">Lorem ipsum</p>

Start mix npm run watch. All files are recompiled, everything works fine. Now let's add new code to the template

<p class="py-4">Lorem ipsum</p>
<p class="py-8">Lorem ipsum</p>

This won't work, because there was no change to the source css / js file, resulting css file did not change and there is no py-8 class inside. Is there any way to tell mix that when the blade template changes, it should recompile css?

sebastiandedeyne commented 4 years ago

This isn't supported.

Why do you need this? This would (vastly) slow down the watch command since it'd need to scan and purge on every change.

xorock commented 4 years ago

The watch command doesn't slow everything down very much on modern computers today, so why would it slow anything down significantly? As I said. if You add new class to the template, compiler does not know it should refresh css file and You won't see py-8 class.

sebastiandedeyne commented 4 years ago

But why are you interested in running Purgecss in watch mode?

xorock commented 4 years ago

For example, purgecss does not parse attributes properly (like input[type="submit"]) so there might be missing styles on prod. I want to know if everything was fine during development process.

sebastiandedeyne commented 4 years ago

The current recommended way to do this is to run a production build locally.

Unfortunately this isn't easy to do since it would require us to set up file watchers for files that don't end up in the webpack bundle (e.g. Blade files).

If this can be achieve with a minimal amount of code, I'm open to adding it. Feel free to send a rough PR with the necessary webpack changes, and I'll see how we can fit it into our API.