Purifying css assets via laravel mix doesnt work

淺唱寂寞╮ 提交于 2020-01-06 05:08:05

问题


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>

回答1:


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.




回答2:


You're setting your options after your processed CSS.

Reverse the order.



来源:https://stackoverflow.com/questions/46074941/purifying-css-assets-via-laravel-mix-doesnt-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!