Ant脚本编译所有(CSS)在DIR LESS文件及子目录犀牛 [英] ANT script to compile all (css) LESS files in a dir and subdirs with RHINO

查看:154
本文介绍了Ant脚本编译所有(CSS)在DIR LESS文件及子目录犀牛的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要不要编译所有的 *。少脚本在一个特定的文件夹,并将其与子目录的不太犀牛1.1.3.js

有在GitHub上做这个特定的文件,它可以完美的例子。但我要一个完整的文件夹,这样做。我尝试了很多,这是我最后一次尝试。

这是不行的, propertyregex ​​似乎不是标准的蚂蚁,我不希望使用这样的事情。我甚至不知道这code会的工作。

 <项目名称=测试默认为主的basedir =../../>
<属性名=css.dir位置=公/ CSS/>
<属性名=tool.less位置=斌/以下/欠犀牛-1.1.3.js/>
<属性名=tool.rhino位置=斌/工具/犀牛/ js.jar/>
< macrodef NAME =lessjs>
    <属性名=输入/>
    <属性名=输出/>
    <&连续GT;
        < Java的罐子=$ {} tool.rhino叉=真输出=@ {}输出>
            < ARG PATH =$ {} tool.less/>
            < ARG路径=@ {}输入/>
        < / JAVA>
        <回声> Lessjs:产生@ {}输出与LT; /回声>
    < /顺序>
< / macrodef><目标名称=主>
     <回声>编制较少的CSS< /回声>
     <文件集DIR =$ {} css.dirID =MYFILE>
          <文件名NAME =** / *少。/>
     < /文件集>
     <属性名=lessfilenameREFID =MYFILE/>
     < propertyregex财产=cssfilename
          输入=$ {} lessfile
          正则表达式=^(。*)\\。少$
          取代=^ \\ 1 \\ $的CSS
          = CASESENSITIVE真/>
     < lessjs输入=lessfile输出=cssfilename/>
< /目标与GT;
< /项目>


解决方案

您可以使用<文件集> 来包括所有的文件需要进行编译。后来,你可以使用<映射器GT; 标记相应的detination CSS 文件。

 <项目名称=测试默认为主的basedir =../../>
<属性名=css.dir位置=公/ CSS/>
<属性名=tool.less位置=斌/以下/欠犀牛-1.1.3.js/>
<属性名=tool.rhino位置=斌/工具/犀牛/ js.jar/>  <目标名称=少说明=转换少CSS然后串联和缩减大小的样式表>  <回声消息=到CSS转换LESS .../>
  <! - 清除原编译css文件 - >
      <删除includeemptydirs =真正的>
            <文件集DIR =$ {} css.dir包括=* CSS,** / * CSS。defaultexcludes =FALSE/>
      < /删除>      <申请DIR =$ {} css.dir可执行=java的平行=假failonerror =真>
  <! - 给少的文件输入包 - >
          <文件集DIR =$ {} css.dir>
              <包括姓名=*少。/>
          < /文件集>
          < ARG值= - 罐子/>
          < ARG PATH =$ {} tool.rhino/>
          < ARG PATH =$ {} tool.less/>
          < SRCFILE />
  <! - 输出与对应的名字编译后的css文件 - >
          <映射器类型=从=水珠,*更少。为=$ {css.dir} / * CSS。/>
          <的TargetFile />
      < /应用>  < /目标与GT;< /项目>

I want do compile all *.less scripts in a specific folder and it subdirs with less-rhino-1.1.3.js.

There is an example on github for doing this for a specific file, which works perfect. But I want to do the same for a complete folder. I tried a lot, here is my last try.

It doesn't work, propertyregex seems not to be standard ANT, I don't want to use such things. I am not even sure if this code would work.

<project name="test" default="main" basedir="../../">
<property name="css.dir" location="public/css"/>
<property name="tool.less" location="bin/less/less-rhino-1.1.3.js"/>
<property name="tool.rhino" location="bin/tools/rhino/js.jar"/>
<macrodef name="lessjs">
    <attribute name="input" />
    <attribute name="output" />
    <sequential>
        <java jar="${tool.rhino}" fork="true" output="@{output}">
            <arg path="${tool.less}"/>
            <arg path="@{input}"/>
        </java>
        <echo>Lessjs: generated @{output}</echo>
    </sequential>
</macrodef>

<target name="main">
     <echo>compiling less css</echo>
     <fileset dir="${css.dir}" id="myfile">
          <filename name="**/*.less" />
     </fileset>
     <property name="lessfilename" refid="myfile"/>
     <propertyregex property="cssfilename"
          input="${lessfile}"
          regexp="^(.*)\.less$"
          replace="^\1\.css$" 
          casesensitive="true" />
     <lessjs input="lessfile" output="cssfilename"/>
</target>
</project>

解决方案

You could use the <fileset> to include all the less files need to be compiled. Later, you could use<mapper> to mark the corresponding detination css file.

<project name="test" default="main" basedir="../../">
<property name="css.dir" location="public/css"/>
<property name="tool.less" location="bin/less/less-rhino-1.1.3.js"/>
<property name="tool.rhino" location="bin/tools/rhino/js.jar"/>

  <target name="less" description="Convert LESS to CSS then concatenate and Minify any stylesheets">

  <echo message="Converting LESS to CSS..."/>
  <!-- Clear the former compiled css files -->
      <delete includeemptydirs="true">
            <fileset dir="${css.dir}" includes="*.css, **/*.css" defaultexcludes="false"/>
      </delete>

      <apply dir="${css.dir}" executable="java" parallel="false" failonerror="true">
  <!-- Give the input bundle of less files-->
          <fileset dir="${css.dir}">
              <include name="*.less"/>
          </fileset>
          <arg value="-jar" />
          <arg path="${tool.rhino}" />
          <arg path="${tool.less}" />
          <srcfile/>
  <!-- Output the compiled css file with corresponding name -->
          <mapper type="glob" from="*.less" to="${css.dir}/*.css"/>
          <targetfile/>
      </apply>

  </target>

</project>

这篇关于Ant脚本编译所有(CSS)在DIR LESS文件及子目录犀牛的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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