clean-css压缩,Clean-CSS基于Node.js的CSS代码压缩工具

Clean-CSS 是一个非常简单的 CSS 压缩程序,基于Node.js环境开发使用,可以删除 CSS 中一些无用的空格、评论以及每个选择器后面的分号,还可以压缩通过 @import 引入的 CSS 文件。

Clean-CSS 基于 Node.js 的 CSS 代码压缩工具

环境依赖

Node.js 4.0+ (tested on CentOS, Ubuntu, OS X, and Windows)

通过Npm安装

npm install clean-css

如何使用命令行

Clean-CSS接受下列命令行参数,使用时请将需要优化的CSS文件放置到最后一个参数后面,避免遇到潜在的不可预想的问题。

cleancss [options] source-file, [source-file, ...]

-h, --help                     output usage information

-v, --version                  output the version number

-b, --keep-line-breaks         Keep line breaks

-c, --compatibility [ie7|ie8]  Force compatibility mode (see Readme for advanced examples)

-d, --debug                    Shows debug information (minification time & compression efficiency)

-o, --output [output-file]     Use [output-file] as output instead of STDOUT

-r, --root [root-path]         Set a root path to which resolve absolute @import rules

-s, --skip-import              Disable @import processing

-t, --timeout [seconds]        Per connection timeout when fetching remote @imports (defaults to 5 seconds)

--rounding-precision [n]       Rounds to `N` decimal places. Defaults to 2. -1 disables rounding

--s0                           Remove all special comments, i.e. /*! comment */

--s1                           Remove all special comments but the first one

--semantic-merging             Enables unsafe mode by assuming BEM-like semantic stylesheets (warning, this may break your styling!)

--skip-advanced                Disable advanced optimizations - ruleset reordering & merging

--skip-aggressive-merging      Disable properties merging based on their order

--skip-import-from [rules]     Disable @import processing for specified rules

--skip-media-merging           Disable @media merging

--skip-rebase                  Disable URLs rebasing

--skip-restructuring           Disable restructuring optimizations

--skip-shorthand-compacting    Disable shorthand compacting

--source-map                   Enables building input's source map

--source-map-inline-sources    Enables inlining sources inside source maps

使用举例

To minify a public.css file into public-min.css do:

cleancss -o public-min.css public.css

To minify the same public.css into the standard output skip the -o parameter:

cleancss public.css

More likely you would like to concatenate a couple of files. If you are on a Unix-like system:

cat one.css two.css three.css | cleancss -o merged-and-minified.css

On Windows:

type one.css two.css three.css | cleancss -o merged-and-minified.css

Or even gzip the result at once:

cat one.css two.css three.css | cleancss | gzip -9 -c > merged-minified-and-gzipped.css.gz

相关链接

Github地址:https://github.com/jakubpawlowicz/clean-css

基于的在线服务:

http://refresh-sf.com/

http://a

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值