使用nodejs如何压缩js,css静态资源

  • 来源: 阿里西西   2016-04-21/09:48
  • 1.[js压缩]uglifyjs source.js -mc -o target.min.js

    以压缩angular.js为例,可以压缩局部变量名,去掉无用的局部变量,空白符等,压缩比例接近80%,效率不错

    [user_00@localhost ~]$ uglifyjs angular.js -mc -o angular.min.js

    WARN: Dropping unused function isBoolean [angular.js:416,9]

    WARN: Dropping unused function makeMap [angular.js:446,9]

    WARN: Dropping unused function size [angular.js:488,9]

    WARN: Dropping unused function isLeafNode [angular.js:523,9]

    WARN: Dropping unused function argument boundTranscludeFn [angular.js:4682,27]

    WARN: Dropping unused function argument rootElement [angular.js:4681,16]

    WARN: Dropping unused function argument nodeList [angular.js:4680,17]

    WARN: Dropping unused function argument scope [angular.js:4679,22]

    WARN: Dropping unused function nodesetLinkingFn [angular.js:4678,9]

    WARN: Dropping unused function argument boundTranscludeFn [angular.js:4690,27]

    WARN: Dropping unused function argument rootElement [angular.js:4689,16]

    WARN: Dropping unused function argument node [angular.js:4688,13]

    WARN: Dropping unused function argument scope [angular.js:4687,22]

    WARN: Dropping unused function argument nodesetLinkingFn [angular.js:4686,25]

    WARN: Dropping unused function directiveLinkingFn [angular.js:4685,9]

    WARN: Dropping unused function stripHash [angular.js:5009,9]

    WARN: Dropping unused variable NG_SWITCH [angular.js:13857,4]

    WARN: Dropping unused variable fns [angular.js:1536,8]

    WARN: Dropping unused variable events [angular.js:1536,13]

    WARN: Dropping unused function wrongMode [angular.js:3879,13]

    WARN: Dropping unused function argument cause [angular.js:4799,31]

    WARN: Dropping unused function argument exception [angular.js:4799,20]

    WARN: Dropping unused function argument args [angular.js:8165,28]

    WARN: Dropping unused function argument args [angular.js:8231,33]

    WARN: Dropping unused function argument names [angular.js:9018,32]

    WARN: Dropping unused function argument name [angular.js:9030,40]

    WARN: Dropping unused variable value [angular.js:9230,14]

    WARN: Dropping unused function argument value [angular.js:12475,36]

    [user_00@localhost ~]$ ls -lh angular.*

    -rw-rw-r-- 1 user_00 user_00 479K Apr 5 01:53 angular.js

    -rw-rw-r-- 1 user_00 user_00 79K May 4 16:09 angular.min.js

    2.[css压缩]sqwish style.css –strict

    sqwish目前看来压缩比例不高。

    [user_00@localhost ~]$ sqwish style.css --strict

    [user_00@localhost ~]$ ls -lh style.*

    -rw-rw-r-- 1 user_00 user_00 5.8K Dec 14 10:40 style.css

    -rw-rw-r-- 1 user_00 user_00 5.5K May 4 16:14 style.min.css

    3.待续——图片压缩工具


    评论 {{userinfo.comments}}

    {{money}}

    {{question.question}}

    A {{question.A}}
    B {{question.B}}
    C {{question.C}}
    D {{question.D}}
    提交

    驱动号 更多