Gruntjs Grunt无法编译JST
我正在尝试为一个使用主干网的项目使用JST模板。一切似乎都正常,但我遇到了一个语法错误,我无法理解 这是控制台输出的内容:Gruntjs Grunt无法编译JST,gruntjs,jst,Gruntjs,Jst,我正在尝试为一个使用主干网的项目使用JST模板。一切似乎都正常,但我遇到了一个语法错误,我无法理解 这是控制台输出的内容: Running "jst:compile" (jst) task >> SyntaxError: Unexpected token = Warning: JST failed to compile. Use --force to continue. Aborted due to warnings. 使用--verbose运行 这是它试图编译的文件: <
Running "jst:compile" (jst) task
>> SyntaxError: Unexpected token =
Warning: JST failed to compile. Use --force to continue.
Aborted due to warnings.
使用--verbose运行
这是它试图编译的文件:
<!-- IDEA START -->
<div class="ideadata" data-id="<%= id %>" data-date="<%= this.date %>" data-votes="<%= this.votes %>">
<!-- Id -->
<span class="id">#<%= this.id %></span>
<!-- Idea -->
<p><%= this.content %></p>
<!-- Voting and social options -->
<div class="social">
<!-- VOTER -->
<!-- HTML -->
<!-- END -->
<a href="#" onclick="window.open(
'https://twitter.com/intent/tweet?original_referer=' + encodeURIComponent(location.href) + '&screen_name=roskildefestival&text=<%= this.content %>&tw_p=tweetbutton',
'twitter-share-dialog',
'width=550,height=390');
return false;"><img src="http://cdn3.iconfinder.com/data/icons/picons-social/57/03-twitter-20.png" /></a>
<a href="#" onclick="window.open(
'https://www.facebook.com/sharer/sharer.php?u=' + encodeURIComponent(location.href),
'facebook-share-dialog',
'width=626,height=436');
return false;"><img src="http://cdn3.iconfinder.com/data/icons/wpzoom-developer-icon-set/500/01-20.png" /></a>
</div>
</div>
<!-- IDEA END -->
<div><%= this.id; %></div>
#
我已尝试替换我想我发现了您的错误:
<!-- IDEA START -->
<div class="ideadata" data-id="<%= id %>"
对于任何遇到这一问题的人,答案都在评论中提到的github问题中。[github.com/gruntjs/grunt contrib jst/issues/29]
答案是:
如果您想像u.template一样解析模板,则不能覆盖templateSettings
所以我改变了这个:
jst: {
compile: {
options: {
templateSettings: {
interpolate : /\{\{(.+?)\}\}/g
}
},
files: {
"<%= buildDir %>/templates.js": ["source.html"]
}
}
}
jst:{
汇编:{
选项:{
模板设置:{
内插:/\{(.+?)\}\}/g
}
},
档案:{
“/templates.js”:[“source.html”]
}
}
}
为此:
jst: {
compile: {
options: {
},
files: {
"<%= buildDir %>/templates.js": ["source.html"]
}
}
}
jst:{
汇编:{
选项:{
},
档案:{
“/templates.js”:[“source.html”]
}
}
}
Trygrunt jst:compile--stack
,因为它应该为您提供有关错误起源的堆栈跟踪。尝试使用--verbose运行它,但使用--stack时未发生任何问题。我更新了问题以匹配它的输出。我不明白为什么这被否决了。投票支持,我认为这是一个很好的问题。实际上我刚刚删除了这个。因为我想确保它不会引起任何麻烦。我也有同样的错误。嗯,你有没有试着把整个代码块(文件)切掉,然后一部分一部分地插入(看看什么时候会发生错误),我知道这是最基本的,但那样你可能会发现冲突?是的。我用从中得到的结果更新了我的问题,但即使是最简单的形式也失败了。我在他们的github上提交了一个问题:我明白了:“的范围可能是这个。
不可用?也许您必须使用对象的名称
?但是在这里真的帮不了你,很抱歉,它不应该真的与编译它有任何关系,因为我会得到一个javascript错误。我只能等着看这个问题!太棒了,至少对我来说,这是正确的答案。
<!-- IDEA START -->
<div class="ideadata" data-id="<%= id %>"
jst: {
compile: {
options: {
templateSettings: {
interpolate : /\{\{(.+?)\}\}/g
}
},
files: {
"<%= buildDir %>/templates.js": ["source.html"]
}
}
}
jst: {
compile: {
options: {
},
files: {
"<%= buildDir %>/templates.js": ["source.html"]
}
}
}