3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

未使用のstyleを排除したcssを生成する

3
Last updated at Posted at 2019-10-09

chromeの拡張機能で、cssやjsの利用状況を確認することができ、解析結果をexportすることができます。
https://umaar.com/dev-tips/187-code-coverage-export/

exportしたjsonは下記コードで、未使用箇所を排除したcssを取得することができます。

$json = json_decode(file_get_contents('Coverage-20191010T053906.json'));

//数字2は、何番目のcssを対象とするかを指定
$json = $json[2];
$out = '';
foreach ($json->ranges as $range) {
    $out .= substr($json->text, $range->start, ($range->end - $range->start))." \n";
}
echo '<pre>';
echo $out;
echo '</pre>';
3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?