自动化Eclipse“Yui Compressor ...” [英] Automate Eclipse "Yui Compressor..."

查看:201
本文介绍了自动化Eclipse“Yui Compressor ...”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Eclipse PDT 在文件的上下文菜单中有这个方便的内置 Yui Compressor 。但是当构建使用多个这样的文件的webapp时,每次更新后手动压缩文件变得很麻烦。它甚至不记得什么文件压缩到哪个文件名,所以你必须再次输入。



是否可以在Eclipse中轻松自动化这个过程,所以你可以点击构建或某些东西,所有指定的文件将被压缩到目标?



Eclipse中关于这个Yui功能的文档真的有一个真空。 >

我正在使用Eclipse Indigo 3.7.0与PDT 3.0.0.v20110516-11,但PDT和Yui选项都保持非常相似,因为伽利略



-update -



自动化解决方案,而不是Eclipse-native,但是关闭:




  • GNU make makefile

     % -  min.js:%.js 
    $ {java} -jar $ {compress} $< -o $ {<:。js = -min.js}


  • Windows批处理

      FOR%f IN(* .js)DO java -jar yuicompressor.jar%f -o deploy\%f 


  • Linux Shellscript

      ls -1 * .js | awk'{printf(java -jar yuicompressor.jar%s -o deploy /%s,$ 1,$ 1)}'| / bin / sh 


  • ANT文件



    参见这里:
    http:// www.ubik-ingenierie.com/ubikwiki/index.php?title=Minifying_JS/CSS

    如何在这里粘贴html / xml?




另请参阅这个问题。

解决方案

嗯,我实际上下载了jar并创建了一个用于CSS和JS压缩的ANT任务。我在Tomcat上工作,所以它包括上传东西,干净的工作/目录和类似的东西。希望它有帮助。

 <?xml version =1.0encoding =UTF-8?> 
<!DOCTYPE项目>
< project name =MyProjectdefault =subir>

<! - ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++ - >

< property name =project.namevalue =MyProject/>

< property name =src.dirlocation =src/>
< property name =web.dirlocation =WebContent/>
< property name =lib.dirlocation =WebContent / WEB-INF / lib/>
< property name =bin.dirlocation =WebContent / WEB-INF / classes/>

< property name =minify.dirlocation =minified/>
< property name =minify.sourcedirlocation =$ {skin.dir} / resources //>
<! - < property name =minify.sourcedirlocation =$ {web.dir} / resources //> - >

<! - ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++ - >

< property prefix =envfile =build.properties/>

< path id =project.classpath>
< pathelement location =$ {src.dir}/>
< fileset dir =$ {lib.dir}>
< include name =*。jar/>
< / fileset>
< / path>

< path id =yui.classpath.minifier>
< fileset dir =$ {lib.dir}>
< include name =YUIAnt.jar/>
< include name =yuicompressor-2.4.2.jar/>
< / fileset>
< / path>

<! - ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++ - >

< target name =checkTomcatHome>
< condition property =local.tomcathome.exists>
< available file =$ {env.TOMCAT_PRUEBAS}type =dir/>
< / condition>
< / target>

< target name =subirdepends =checkTomcatHomeif =local.tomcathome.exists>

< echo message =El servidor Tomcat destino existse,buscando archivos para copia en el proyecto y en en OsmoCore / WebContent .../>

< copy todir =$ {env.TOMCAT_PRUEBAS} / webapps / $ {project.name}>
< fileset dir =$ {web.dir}>
< include name =** / *。*/>
< / fileset>
< / copy>

<! - < echo message =Buscando archivos para copia en $ {env.TOMCAT_PRUEBAS} / webapps / $ {project.name} / WEB-INF / classes ... >
< copy todir =$ {env.TOMCAT_PRUEBAS} / webapps / $ {project.name} / WEB-INF / classes>
< fileset dir =$ {bin.dir}>
< include name =** / *。*/>
< / fileset>
< / copy> - >

< / target>

<! - ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++ - >

< target name =WAR>

< delete file =$ {project.name} .war/>
< delete dir =TMP_WAR/>
< mkdir dir =TMP_WAR/>


< copy todir =TMP_WAR>
< fileset dir =$ {web.dir}>
< include name =** / *。*/>
< / fileset>
< / copy>

< copy todir =TMP_WAR / WEB-INF / classes>
< fileset dir =$ {bin.dir}>
< include name =** / *。*/>
< / fileset>
< / copy>

< delete dir =$ {project.name} .war/>

< zip destfile =$ {project.name} .war>
< zipfileset dir =TMP_WAR>
< include name =** / *。*/>
< / zipfileset>
< / zip>

< delete dir =TMP_WAR/>

< / target>

<! - ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++ - >

< target name =subirCompletodepends =checkTomcatHomeif =local.tomcathome.exists>
< echo message =El servidor Tomcat destino existse,buscando carpetas工作y $ {project.name} en Webapps,para Eliminar/>
< delete dir =$ {env.TOMCAT_PRUEBAS} / work/>
< delete dir =$ {env.TOMCAT_PRUEBAS} / webapps / $ {project.name}/>
< antcall target =subir/>
< / target>

<! - ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++ - >

< target name =borrarWorkdepends =checkTomcatHomeif =local.tomcathome.exists>
< echo message =El servidor Tomcat destino存在,buscando carpeta工作淘汰.../>
< delete dir =$ {env.TOMCAT_PRUEBAS} / work/>
< / target>

<! - ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++ - >

< target name =css.minify>

< echo message =Creando directorio temporal $ {minify.dir}(si no existeaún).../>
< mkdir dir =$ {minify.dir}/>

< echo message =Borrandoversiónanterior de la carpeta temporal $ {minify.dir} / css-min / .../>
< delete dir =$ {minify.dir} / css-min //>
< echo message =Creando carpeta temporal $ {minify.dir} / css-min / .../>
< mkdir dir =$ {minify.dir} / css-min //>

< echo message =Copiando estructura de $ {web.dir} / resources / styles / en carpeta temporal .../>
< copy todir =$ {minify.dir} / css-min />
< fileset dir =$ {minify.sourcedir} / styles />
< include name =** / *。*/>
< / fileset>
< / copy>

< echo message =Borrando los CSS copiados a la carpeta temporal .../>
< delete>
< fileset dir =$ {minify.dir} / css-min />
< include name =** / *。css/>
< / fileset>
< / delete>

< echo message =Comprimiendo !!! .../>
< apply executable =javaparallel =falsedest =$ {minify.dir} / css-min />
< fileset dir =$ {minify.sourcedir} / styles />
< include name =** / *。css/>
< / fileset>
< arg line = - jar/>
< arg path =$ {lib.dir} /yui_compressor/yuicompressor-2.4.7.jar/>
< arg line = - line-break 0/>
< arg line = - type css/>
< arg line = - 字符集ISO-8859-1/>
< arg line = - nomunge/>
<! - < arg line = - -verbose/> - >
< srcfile />
< arg line = - o/>
< mapper type =globfrom =*。cssto =*。css/>
< targetfile />
< / apply>
< / target>

<! - ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++ - >

< target name =js.minify>

< echo message =Creando directorio temporal $ {minify.dir}(si no existeaún).../>
< mkdir dir =$ {minify.dir}/>

< echo message =Borrandoversiónanterior de la carpeta temporal $ {web.dir} / resources / js-min / .../>
< delete dir =$ {minify.dir} / js-min //>
< echo message =Creando carpeta temporal $ {web.dir} / resources / js-min / .../>
< mkdir dir =$ {minify.dir} / js-min //>

< echo message =Copiando estructura de $ {web.dir} / resources / scripts / en carpeta temporal .../>
< copy todir =$ {minify.dir} / js-min />
< fileset dir =$ {minify.sourcedir} / scripts />
< include name =** / *。*/>
< / fileset>
< / copy>

< echo message =Borrando los JS copiados a la carpeta temporal .../>
< delete>
< fileset dir =$ {minify.dir} / js-min />
< include name =** / *。js/>
< / fileset>
< / delete>

< echo message =Comprimiendo !!! .../>
< apply executable =javaparallel =falsedest =$ {minify.dir} / js-min />

< fileset dir =$ {minify.sourcedir} / scripts>
< include name =** / *。js/>
< / fileset>
< arg line = - jar/>
< arg path =$ {lib.dir} /yui_compressor/yuicompressor-2.4.7.jar/>
< arg line = - line-break 0/>
< arg line = - type js/>
< arg line = - 字符集ISO-8859-1/>
< arg line = - nomunge/>
<! - < arg line = - -verbose/> - >
< srcfile />
< arg line = - o/>
< mapper type =globfrom =*。jsto =*。js/>
< targetfile />
< / apply>

< / target>

<! - ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++ - >

< target name =js.minified.subirdepends =checkTomcatHomeif =local.tomcathome.exists>
< echo message =El servidor Tomcat destino existse,copiando archivos'encogidos'a $ {env.TOMCAT_PRUEBAS} / webapps / $ {project.name} / resources / scripts .../>
< copy todir =$ {env.TOMCAT_PRUEBAS} / webapps / $ {project.name} / resources / scriptsoverwrite =yes>
< fileset dir =$ {minify.dir} / js-min />
< include name =** / *。*/>
< / fileset>
< / copy>
< / target>

<! - ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++ - >

< target name =css.minified.subirdepends =checkTomcatHomeif =local.tomcathome.exists>
< echo message =El servidor Tomcat destino existse,copiando archivos'encogidos'a $ {env.TOMCAT_PRUEBAS} / webapps / $ {project.name} / resources / styles .../>
< copy todir =$ {env.TOMCAT_PRUEBAS} / webapps / $ {project.name} / resources / stylesoverwrite =yes>
< fileset dir =$ {minify.dir} / css-min />
< include name =** / *。*/>
< / fileset>
< / copy>
< / target>

<! - ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++ - >

< target name =css.minified.process>
< echo message =Reduciendo eltamañode los archivos CSS .../>
< antcall target =css.minify/>

< echo message =Cargando los archivos CSS .../>
< antcall target =css.minified.subir/>

< echo message =Borrando la carpeta temporal .../>
< delete dir =$ {minify.dir}/>
< / target>

<! - ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++ - >

< target name =js.minified.process>
< echo message =Reduciendo eltamañode los archivos JS .../>
< antcall target =js.minify/>

< echo message =Cargando los archivos JS .../>
< antcall target =js.minified.subir/>

< echo message =Borrando la carpeta temporal .../>
< delete dir =$ {minify.dir}/>
< / target>
<! - +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++ - >

< / project>


Eclipse PDT has this handy built-in Yui Compressor in the context menu for files. But when building a webapp that uses multiple such files, it becomes tedious to compress the files manually after each update. It doesn't even remember what files compress to which filenames, so you have to enter that again.

Is it possible to automate this process easily within Eclipse, so you can click on "build" or something and all specified files will be compressed to their targets?

There is really a vacuum concerning documentation about this Yui feature in Eclipse.

I am using Eclipse Indigo 3.7.0 with PDT 3.0.0.v20110516-11, but both PDT and the Yui option have remained pretty similar since Galileo

-update-

Automation solutions, not Eclipse-native but close:

  • GNU make makefile

    %-min.js: %.js
        ${java} -jar ${compressor} $< -o ${<:.js=-min.js}
    

  • Windows Batch

    FOR %f IN (*.js) DO java -jar yuicompressor.jar %f -o deploy\%f
    

  • Linux Shellscript

    ls -1 *.js | awk '{printf("java -jar yuicompressor.jar %s -o deploy/%s",$1,$1)}' | /bin/sh
    

  • ANT file

    See here: http://www.ubik-ingenierie.com/ubikwiki/index.php?title=Minifying_JS/CSS
    How do I paste html/xml here?

Also see this question.

解决方案

Well, I actually downloaded the jar and created an ANT task to to CSS and JS compression. I work on Tomcat, so it includes tasks to upload stuff, clean work/ directory and things like that. Hope it helps.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE project>
<project name="MyProject" default="subir">

    <!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-->

    <property name="project.name" value="MyProject" />

    <property name="src.dir" location="src" />
    <property name="web.dir" location="WebContent" />
    <property name="lib.dir" location="WebContent/WEB-INF/lib" />
    <property name="bin.dir" location="WebContent/WEB-INF/classes" />

    <property name="minify.dir" location="minified" />
    <property name="minify.sourcedir" location="${skin.dir}/resources/" />
    <!-- <property name="minify.sourcedir" location="${web.dir}/resources/" /> -->

    <!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-->

    <property prefix="env" file="build.properties" />

    <path id="project.classpath">
        <pathelement location="${src.dir}" />
        <fileset dir="${lib.dir}">
            <include name="*.jar" />
        </fileset>
    </path>

    <path id="yui.classpath.minifier">
        <fileset dir="${lib.dir}">
            <include name="YUIAnt.jar" />
            <include name="yuicompressor-2.4.2.jar" />
        </fileset>
    </path>

    <!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-->

    <target name="checkTomcatHome">
        <condition property="local.tomcathome.exists">
            <available file="${env.TOMCAT_PRUEBAS}" type="dir" />
    </condition>
    </target>

    <target name="subir" depends="checkTomcatHome" if="local.tomcathome.exists">

        <echo message="El servidor Tomcat destino existe, buscando archivos para copia en el proyecto y en en OsmoCore/WebContent..." />

        <copy todir="${env.TOMCAT_PRUEBAS}/webapps/${project.name}">
            <fileset dir="${web.dir}">
                <include name="**/*.*" />
            </fileset>
        </copy>

        <!--<echo message="Buscando archivos para copia en ${env.TOMCAT_PRUEBAS}/webapps/${project.name}/WEB-INF/classes..." />
        <copy todir="${env.TOMCAT_PRUEBAS}/webapps/${project.name}/WEB-INF/classes">
            <fileset dir="${bin.dir}">
                <include name="**/*.*" />
            </fileset>
        </copy>-->

    </target>

    <!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-->

    <target name="WAR">

        <delete file="${project.name}.war"/>
        <delete dir="TMP_WAR"/>
        <mkdir dir="TMP_WAR"/>


        <copy todir="TMP_WAR">
            <fileset dir="${web.dir}">
                <include name="**/*.*" />
            </fileset>
        </copy>

        <copy todir="TMP_WAR/WEB-INF/classes">
            <fileset dir="${bin.dir}">
                <include name="**/*.*" />
            </fileset>
        </copy>

        <delete dir="${project.name}.war"/>

        <zip destfile="${project.name}.war">
            <zipfileset dir="TMP_WAR">
                <include name="**/*.*" />
            </zipfileset>
        </zip>

        <delete dir="TMP_WAR"/>

    </target>

    <!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-->

    <target name="subirCompleto" depends="checkTomcatHome" if="local.tomcathome.exists">
        <echo message="El servidor Tomcat destino existe, buscando carpetas Work y ${project.name} en Webapps, para eliminar" />
        <delete dir="${env.TOMCAT_PRUEBAS}/work" />
        <delete dir="${env.TOMCAT_PRUEBAS}/webapps/${project.name}" />
        <antcall target="subir" />
    </target>

    <!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-->

    <target name="borrarWork" depends="checkTomcatHome" if="local.tomcathome.exists">
        <echo message="El servidor Tomcat destino existe, buscando carpeta Work a eliminar..." />
        <delete dir="${env.TOMCAT_PRUEBAS}/work"/>
    </target>

    <!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-->

    <target name="css.minify">

        <echo message="Creando directorio temporal ${minify.dir} (si no existe aún)..." />
        <mkdir dir="${minify.dir}" />

        <echo message="Borrando versión anterior de la carpeta temporal ${minify.dir}/css-min/..." />
        <delete dir="${minify.dir}/css-min/" />
        <echo message="Creando carpeta temporal ${minify.dir}/css-min/..." />
        <mkdir dir="${minify.dir}/css-min/" />

        <echo message="Copiando estructura de ${web.dir}/resources/styles/ en carpeta temporal..." />
        <copy todir="${minify.dir}/css-min/">
            <fileset dir="${minify.sourcedir}/styles/">
                <include name="**/*.*" />
            </fileset>
        </copy>

        <echo message="Borrando los CSS copiados a la carpeta temporal..." />
        <delete>
            <fileset dir="${minify.dir}/css-min/" >
                <include name="**/*.css"/>
            </fileset>
        </delete>

        <echo message="Comprimiendo!!!..." />
        <apply executable="java" parallel="false" dest="${minify.dir}/css-min/">
            <fileset dir="${minify.sourcedir}/styles/">
                <include name="**/*.css"/>
            </fileset>
            <arg line="-jar"/>
            <arg path="${lib.dir}/yui_compressor/yuicompressor-2.4.7.jar"/>
            <arg line="--line-break 0"/>
            <arg line="--type css"/>
            <arg line="--charset ISO-8859-1"/>
            <arg line="--nomunge"/>
            <!-- <arg line="- -verbose"/> -->
            <srcfile />
            <arg line="-o"/>
            <mapper type="glob" from="*.css" to="*.css"/>
            <targetfile />
        </apply>
    </target>

    <!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-->

    <target name="js.minify">

        <echo message="Creando directorio temporal ${minify.dir} (si no existe aún)..." />
        <mkdir dir="${minify.dir}" />

        <echo message="Borrando versión anterior de la carpeta temporal ${web.dir}/resources/js-min/..." />
        <delete dir="${minify.dir}/js-min/" />
        <echo message="Creando carpeta temporal ${web.dir}/resources/js-min/..." />
        <mkdir dir="${minify.dir}/js-min/" />

        <echo message="Copiando estructura de ${web.dir}/resources/scripts/ en carpeta temporal..." />
        <copy todir="${minify.dir}/js-min/">
            <fileset dir="${minify.sourcedir}/scripts/">
                <include name="**/*.*" />
            </fileset>
        </copy>

        <echo message="Borrando los JS copiados a la carpeta temporal..." />
        <delete>
            <fileset dir="${minify.dir}/js-min/" >
                <include name="**/*.js"/>
            </fileset>
        </delete>

        <echo message="Comprimiendo!!!..." />
        <apply executable="java" parallel="false" dest="${minify.dir}/js-min/">

            <fileset dir="${minify.sourcedir}/scripts">
                <include name="**/*.js"/>
            </fileset>
            <arg line="-jar"/>
            <arg path="${lib.dir}/yui_compressor/yuicompressor-2.4.7.jar"/>
            <arg line="--line-break 0"/>
            <arg line="--type js"/>
            <arg line="--charset ISO-8859-1"/>
            <arg line="--nomunge"/>
            <!--<arg line="- -verbose"/>-->
            <srcfile />
            <arg line="-o"/>
            <mapper type="glob" from="*.js" to="*.js"/>
            <targetfile />
        </apply>

    </target>

    <!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-->

    <target name="js.minified.subir" depends="checkTomcatHome" if="local.tomcathome.exists">
        <echo message="El servidor Tomcat destino existe, copiando archivos 'encogidos' a  ${env.TOMCAT_PRUEBAS}/webapps/${project.name}/resources/scripts..." />
        <copy todir="${env.TOMCAT_PRUEBAS}/webapps/${project.name}/resources/scripts" overwrite="yes">
            <fileset dir="${minify.dir}/js-min/">
                <include name="**/*.*" />
            </fileset>
        </copy>
    </target>

    <!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-->

    <target name="css.minified.subir" depends="checkTomcatHome" if="local.tomcathome.exists">
        <echo message="El servidor Tomcat destino existe, copiando archivos 'encogidos' a  ${env.TOMCAT_PRUEBAS}/webapps/${project.name}/resources/styles..." />
        <copy todir="${env.TOMCAT_PRUEBAS}/webapps/${project.name}/resources/styles" overwrite="yes">
            <fileset dir="${minify.dir}/css-min/">
                <include name="**/*.*" />
            </fileset>
        </copy>
    </target>

    <!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-->

    <target name="css.minified.process">
        <echo message="Reduciendo el tamaño de los archivos CSS..." />
        <antcall target="css.minify" />

        <echo message="Cargando los archivos CSS..." />
        <antcall target="css.minified.subir" />

        <echo message="Borrando la carpeta temporal..." />
        <delete dir="${minify.dir}" />
    </target>

    <!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-->

    <target name="js.minified.process">
        <echo message="Reduciendo el tamaño de los archivos JS..." />
        <antcall target="js.minify" />

        <echo message="Cargando los archivos JS..." />
        <antcall target="js.minified.subir" />

        <echo message="Borrando la carpeta temporal..." />
        <delete dir="${minify.dir}" />
    </target>
    <!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-->

</project>

这篇关于自动化Eclipse“Yui Compressor ...”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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