grunt:如何使用grunt任务替换HTML文件中的路径 [英] grunt: how to replace paths in html file using grunt task
问题描述
在我的grunt配置中,如果有一个变量定义一个包含css文件的目录。现在我想配置一个将这个变量的值插入到html文件中的grunt任务。
例如,我可以想象,我有一个index.html文件,如下所示:
inside my grunt configuration if have a variable which defines a directory which contains a css file. Now I would like to configure a grunt task which insert the value of this variable into a html file. For example, I can imagine that I have an index.html file as follows
<!doctype html>
<head>
<link rel="stylesheet" href="<% pathToCss %>/styles.css">
...
但是我找不到能为我做的任务。任何建议咕tak可以为我做这个?
But I cannot find a task which can do that for me. Any suggestions which grunt taks can do this for me ?
推荐答案
我刚发现可以用grunt.template完成如下所示:
I just found out that it can be done with grunt.template as follows:
template: {
options: {
data: {
pathToCss: './css'
}
},
demo: {
files: [
{ '<%= ./output/index.html': ['<%= ./input/template.html'] }
]
}
},
然后在输入文件(template.html)中定义'pathToCss',如下所示:
And in the input file (template.html) you define 'pathToCss' as follows:
<link rel="stylesheet" href="../../<%- pathToCss %>/styles.css">
但是,如果我查看文档,我没有看到这是在哪里被记录!
However, if I look at the documentation, I don't see where this is documentated!
这篇关于grunt:如何使用grunt任务替换HTML文件中的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!