Compress JS and CSS while deployement

怎甘沉沦 提交于 2019-12-12 09:56:45

问题


I am using ANT to deploy build in to Tomcat Server. I Want to compress the static files CSS and JS only when i deploy to the server.

any suggestion?


回答1:


You can do something like that as part of the build (using YUI Compressor)

<target name="js.minify">
    <apply executable="java" parallel="false">
        <fileset dir="." includes="foo.js, bar.js"/>
        <arg line="-jar"/>
        <arg path="yuicompressor.jar"/>
        <srcfile/>
        <arg line="-o"/>
        <mapper type="glob" from="*.js" to="*-min.js"/>
        <targetfile/>
    </apply>
</target>

<target name="css.minify">
    <apply executable="java" parallel="false">
        <fileset dir="." includes="*.css"/>
        <arg line="-jar"/>
        <arg path="yuicompressor.jar"/>
        <arg line="--line-break 0"/>
        <srcfile/>
        <arg line="-o"/>
        <mapper type="glob" from="*.css" to="*-min.css"/>
        <targetfile/>
    </apply>
</target>

Check out this article for more info: http://www.julienlecomte.net/blog/2007/09/16/




回答2:


This blog post about using YUI compressor to minify JS/CSS using Ant might help you.



来源:https://stackoverflow.com/questions/3826869/compress-js-and-css-while-deployement

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!