我正在尝试使用 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/