【问题标题】:Purifying css assets via laravel mix doesnt work通过 laravel mix 净化 css 资产不起作用
【发布时间】:2018-02-14 22:16:47
【问题描述】:

说明:

编译css文件时净化选项不起作用。你能解释一下这种方法有什么问题吗?

复制步骤:

这是在我的混音文件中:

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,
        }

})

这是我的 css 文件,编译后保持不变:

.unused-class{

  color:red;

}

.used-class{

  color:blue;

}

```

这是在我的刀片文件中:

<!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>

【问题讨论】:

    标签: webpack minify laravel-mix purifycss


    【解决方案1】:

    您在处理完 CSS 后设置选项。

    颠倒顺序。

    【讨论】:

      【解决方案2】:

      purifyOptions 是 purifyCss 属性的一个属性:

      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,
          }
        }
      })
      

      不是超级漂亮,但我相信它会完成工作。

      【讨论】:

      • 这有点晚了,但出于好奇,我稍后会检查一下。谢谢
      【解决方案3】:

      style 只会缩小你的 CSS。它不会对它应用purgeCss

      要清除你的 CSS,你应该将 some.css 重命名为 some.scss

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-02-14
        • 2018-02-06
        • 2018-01-15
        • 1970-01-01
        • 1970-01-01
        • 2019-02-01
        • 2020-11-22
        相关资源
        最近更新 更多