【问题标题】:HTML 5 Boiler plate ant script with absolute paths具有绝对路径的 HTML5 样板蚂蚁脚本
【发布时间】:2012-12-26 16:37:26
【问题描述】:

我正在使用 html5boiler 板 ant 构建脚本,我正在尝试将其集成到我现有的平台中,我所有的 css 和 js 文件都使用绝对路径包含在内。例如:

             <!-- scripts concatenated and minified via build script -->
        <script type="text/javascript" src="/static/js/common.js"></script>
        <script type="text/javascript" src="/static/js/overlay.js"></script>
        <script type="text/javascript" src="/static/js/init.js"></script>
        <script type="text/javascript" src="/static/js/base.js"></script>
        <!-- end scripts -->

但是,当我运行构建脚本时,它告诉我该目录不存在。那是因为它不使用相对路径来查找文件。如果我取下前导 / 那么我可以让它工作,因为它相对于我的项目源文件夹。知道如何在不取消前导斜线的情况下使其工作吗?我们的想法是能够采用现有项目并使其在不进行任何更改的情况下工作,除了添加 cmets。

更新 以下 ANT 代码来自 html5boiler 板 ant build.xml。基本上,我在 file.root.page 中的路径是绝对的,就像上面的静态一样。因此 scripts.ordered 属性正在输出具有绝对路径的文件名。因此,当它到达 concat 命令时,它会输入 script.toconcat ,其中绝对路径以 /static 开头。我需要在这些绝对路径之前添加一个路径,所以我现在有了 /content/test.war/static/js/common.js

所以基本上,我试图在变量 scripts.toconcat 前面添加一个路径,例如 /content/test.war,其背后是上面定义的绝对路径列表。

<filelist id="file.root" dir="${dir.source}/../${dir.cssjsfileloc}" files="${file.root.page}"/>
    <echo message="Concatenating Main JS scripts based on ${file.root.page}..."/>
    <apply executable="java" parallel="false"
      outputproperty="scripts.ordered">
        <arg value="-cp"/>
        <arg value="${dir.build.tools}"/>
        <arg value="ScriptsToConcat"/>
        <first>
            <filelist refid="file.root"/>
        </first>
    </apply>
    <filelist id="scripts.toconcat" dir="./${dir.intermediateroot}/" files="${scripts.ordered}">
    </filelist> 
<!-- overwrite=no here means not to overwrite if the target is newer than the sources -->
    <concat destfile="./${dir.intermediate}/${dir.js}/scripts-concat.min.js" overwrite="no">
        <filelist refid="scripts.toconcat" />
    </concat>

谢谢

【问题讨论】:

    标签: ant html5boilerplate


    【解决方案1】:

    这是蚂蚁。为什么不让 Ant 任务在执行替换之后运行?

    您可以调用replaceregexp,这是一个用于文件搜索和替换的目录节奏任务。

    【讨论】:

    • 我不想编辑文件的内容。我宁愿直接编辑文件列表。检查我上面的蚂蚁任务
    猜你喜欢
    • 2011-02-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多