0

如果我的代码绝对正确,为什么会出现此错误?Grunt 提示错误:

c:\xampp\htdocs\yeoman\ci-test\Grunt < % if(includeLess) { % > ^ 正在加载“Gruntfile.js”任务...错误 >> SyntaxError: Unexpected token < on build

代码:

grunt.registerTask('serve', [
    <% if(includeLess) { %>
    'less',<% } %>
    'express',
    'open',
    'imagemin',
    'watch'
]);
4

1 回答 1

0

<%并且%>是 lodash 模板的开始和结束语句:http ://lodash.com/docs#template,Grunt在配置中使用。

模板只是字符串,这意味着它们必须被包装'"处理grunt.template.processhttp://gruntjs.com/api/grunt.template#grunt.template.process或者当包含在 Grunt 配置中时,它们会自动处理。

但是由于 Gruntfiles 是 javascript,所以您不需要在 Gruntfile 的那部分使用 lodash 模板。只需使用javascript:

var tasks = ['express', 'open', 'imagemin', 'watch'];
if (includeLess) tasks.unshift('less'); // add less to the beginning of array
grunt.registerTask('serve', tasks);
于 2014-02-03T18:06:02.337 回答