使用 grunt 和 processhtml 更新基本 href(不保留部分路径)
Using grunt and processhtml to update base href (without preserving parts of the path)
我正在尝试使用 Grunt 和 processhtml 在 index.html 中更新我的 <base href="path">
。这增加了 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
-option:
Gruntfile 配置:
{
options: {
data: {
distbase: "/ndt/dist-local/
}
},
files: /**/
}
HTML:
<!-- build:remove -->
<base href="/ndt/web/">
<!-- /build -->
<!-- build:template
<base href="<%= distbase %>">
/build -->
我正在尝试使用 Grunt 和 processhtml 在 index.html 中更新我的 <base href="path">
。这增加了 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
-option:
Gruntfile 配置:
{
options: {
data: {
distbase: "/ndt/dist-local/
}
},
files: /**/
}
HTML:
<!-- build:remove -->
<base href="/ndt/web/">
<!-- /build -->
<!-- build:template
<base href="<%= distbase %>">
/build -->