部署时压缩 JS 和 CSS [英] Compress JS and CSS while deployement

查看:44
本文介绍了部署时压缩 JS 和 CSS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 ANT 将构建部署到 Tomcat 服务器.我只想在部署到服务器时压缩静态文件 CSS 和 JS.

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.

有什么建议吗?

推荐答案

作为构建的一部分,您可以执行类似的操作(使用 YUI Compressor)

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>

查看这篇文章了解更多信息:http://www.julienlecomte.net/blog/2007/09/16/

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

这篇关于部署时压缩 JS 和 CSS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆