css分析指什么,csscss: CSSCSS 是一个用来分析 CSS 中冗余信息的工具,通过解析 CSS 文件可以显示出那些规则是重复定义的...

9184afead0c4c6588674111030cbe354.png

b698c677f9393c4b61135e2ff4376942.png

What is it?

csscss will parse any CSS files you give it and let you know which

rulesets have duplicated declarations.

What is it for?

One of the best strategies for me to maintain CSS is to reduce

duplication as much as possible. It's not a silver bullet, but it sure

helps.

To do that, you need to have all the rulesets in your head at all times.

That's hard, csscss is easy. Let it tell you what is redundant.

How do I use it?

First you need to install it. It is currently packaged as a ruby gem:

$ gem install csscss

Note: csscss only works on ruby 1.9.x and up. It will have trouble with ruby 1.8.x.

Then you can run it in at the command line against CSS files.

$ csscss path/to/styles.css path/to/other-styles.css

{.contact .content .primary} and {article, #comments} share 5 rules

{.profile-picture}, {.screenshot img} and {a.blurb img} share 4 rules

{.work h2:first-child, .contact h2} and {body.home h2} share 4 rules

{article.blurb:hover} and {article:hover} share 3 rules

Run it in a verbose mode to see all the duplicated styles.

$ csscss -v path/to/styles.css

Run it against remote files by passing a valid URL.

$ csscss -v http://example.com/css/main.css

You can also choose a minimum number of matches, which will ignore any

rulesets that have fewer matches.

$ csscss -n 10 -v path/to/style.css # ignores rulesets with < 10 matches

If you prefer writing in Sass, you can also parse your sass/scss files.

$ gem install sass

$ csscss path/to/style.scss

Sass users may be interested in the --ignore-sass-mixins

experimental flag that won't match duplicate declarations from including mixins.

If you prefer writing in LESS, you can also parse your LESS files.

$ gem install less

$ csscss path/to/style.less

LESS requires an additional javascript runtime.

v8/therubyracer on most

rubies, and therubyrhino on

jruby.

Are there any community extensions?

compass-csscss integrates csscss with compass projects.

grunt-csscss a grunt task to automatically run csscss.

gulp-csscss a gulp task to automatically run csscss.

Please submit an issue if you know of any others.

Why doesn't csscss automatically remove duplications for me?

I have been asked this a lot, but csscss is intentionally designed this

way. Check out this

post

for my reasoning.

I found bugs

This is still a new and evolving project. I heartily welcome feedback.

If you find any issues, please report them on

github.

Please include the smallest CSS snippet to describe the issue and the

output you expect to see.

I'm a dev, I can help

Awesome! Thanks! Here are the steps I ask:

Fork it

Create your feature branch (git checkout -b my-new-feature)

Commit your changes (git commit -am 'Add some feature')

Make sure the tests pass (bundle exec rake test)

Push to the branch (git push origin my-new-feature)

Create new Pull Request

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值