将 autoprefix-cli 添加到 ANT 构建

Adding autoprefix-cli to ANT build

我正在尝试将 autoprefix-cli 添加到我的 ANT 构建中。下面是我的代码。

<target name="auto">
<apply executable="autoprefixer-cli.bat" verbose="true" force="true" failonerror="true">
    <arg value="-d" /> <!-- Turn on verbose -->
    <arg value="prefix" />
    <arg value="*.css" />  
</apply>
</target>

当我进行 ant 构建时,它给我一个错误,提示未指定资源。

BUILD FAILED
D:\tempTest\AntTestProject\build.xml:25: no resources specified

注意:我可以从命令行访问 autoprefix-cli,它安装了 -g 标志,而且当我直接从命令行使用它时它也可以工作。

apply 任务基本上是在一批资源(文件、目录、URL 等)上循环执行 exec 任务。如果您只想 运行 一个命令,请改用 exec

但是,您可能还需要更改命令。来自 Ant 的 exec 任务文档:

Note that .bat files cannot in general by executed directly. One normally needs to execute the command shell executable cmd using the /c switch.

https://ant.apache.org/manual/Tasks/exec.html

所以你应该:

<exec executable="cmd" verbose="true" force="true" failonerror="true">
    <arg value="/c" />
    <arg value="autoprefixer-cli.bat" />
    <arg value="-d" />
    <arg value="prefix" />
    <arg value="*.css" />  
</exec>