Purifying css assets via laravel mix doesnt work

796 views Asked by At

Description:

Purifying option doesnt work while compiling css files.Can you explain what is wrong with this approach?

Steps To Reproduce:

This is inside my mix file:

mix.style('resources/assets/css/some.css', 'public/css/some.css').options({

  purifyCss: {
            paths: ['/home/smolen/Projects/laravel-test/resources/views/welcome.blade.php'],
            verbose:true,
            minimize:true,
        }

})

This is my css file which stay the same after compiling:

.unused-class{

  color:red;

}

.used-class{

  color:blue;

}

```

This is in my blade file:

<!doctype html>
<html lang="{{ app()->getLocale() }}">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">

        <title>Laravel</title>

        <!-- Fonts -->
        <link href="https://fonts.googleapis.com/css?family=Raleway:100,600" rel="stylesheet" type="text/css">

    </head>
    <body>
      <div class="used-class"></div>
    </body>
</html>
3

There are 3 answers

0
Adam On

style will only minify your css. It won't apply purgeCss to it.

To purge your css, you should rename some.css to some.scss and

mix.options({
  purifyCss: true,
});
mix.sass('resources/assets/css/some.scss', 'public/css/some.css');
0
Darryl E. Clarke On

You're setting your options after your processed CSS.

Reverse the order.

1
Trent Payton On

The purifyOptions are a property of the purifyCss property:

mix.style('resources/assets/css/some.css', 'public/css/some.css').options({
  purifyCss: {
    purifyOptions: {
      paths: ['/home/smolen/Projects/laravel-test/resources/views/welcome.blade.php'],
      verbose:true,
      minimize:true,
    }
  }
})

Not super pretty, but it'll do the job I believe.