javascript - 使用 grunt 和 processhtml 更新基本 href(不保留部分路径)

标签 javascript gruntjs

我正在尝试使用 Grunt 和 processhtml 来更新我的 <base href="path">在index.html中。这增加了 this question这似乎已经死了并且没有公认的答案。另外,那里的答案对我不起作用。

我的index.html中的部分:

<!-- build:[href] /ndt/dist-local/ -->
<base href="/ndt/web/">
<!-- /build -->

结果是:

<base href="/ndt/dist-local/web">

我想要出来的是:

<base href="/ndt/dist-local/">

它添加到 Web 部件上(不带斜杠)。我怎样才能让它不发生?

最佳答案

解决 <!-- build:<attr> <target> -->始终包括最后一部分,您可以使用 remove 的组合和template :

    <!-- build:remove -->
        <base href="/ndt/web/">
    <!-- /build -->

    <!-- build:template
        <base href="/ndt/dist-local/">
    /build -->

这不是最漂亮的选择,但它确实有效。如果您想让它更加动态,您可以将 dist-base 包含为 data -选项:

Gruntfile 配置:

{
  options: {
    data: {
      distbase: "/ndt/dist-local/
    }
  },
  files: /**/
}

HTML:

<!-- build:remove -->
    <base href="/ndt/web/">
<!-- /build -->

<!-- build:template
    <base href="<%= distbase %>">
/build -->

关于javascript - 使用 grunt 和 processhtml 更新基本 href(不保留部分路径),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32262361/

相关文章:

javascript - Systemjs 配置在 Angular2 中加载 templateUrl

css - 如何防止 compass 处理并替换我的变量的 unicode 值?

javascript - 具有非核心检测的自定义 grunt-modernizr

angularjs - 使用 grunt 和 r.js/requirejs 手动引导

gruntjs - 如何使用 grunt-contrib-concat 和 grunt-contrib-uglify 为每个单独的 js 文件创建源映射?

dependencies - 咕噜声/bower/组件 : Handling dependencies?

javascript - 加载时如何更新 Angular2.RC1 子组件?

javascript - 处理 JS svg 加载 - Google Appengine

javascript - 如何从WinJS/javascript使用WebView控件navigateToLocalStreamUri

javascript - 将 PHP 数据传递给 Ajax 响应?