使用 RHINO 编译目录和子目录中所有(css)LESS 文件的 ANT 脚本 [英] ANT script to compile all (css) LESS files in a dir and subdirs with RHINO

查看:29
本文介绍了使用 RHINO 编译目录和子目录中所有(css)LESS 文件的 ANT 脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想编译特定文件夹中的所有 *.less 脚本,并使用 less-rhino-1.1.3.js 子目录.

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

github 上有一个针对特定文件执行此操作的示例,效果很好.但我想对一个完整的文件夹做同样的事情.我尝试了很多,这是我最后一次尝试.

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.

不行,propertyregex好像不是标准的ANT,我不想用这样的东西.我什至不确定这段代码是否有效.

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>

推荐答案

您可以使用 来包含所有需要编译的 less 文件.稍后,您可以使用 来标记相应的定义css 文件.

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>

这篇关于使用 RHINO 编译目录和子目录中所有(css)LESS 文件的 ANT 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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