Gruntjs Grunt生成上的语法错误

Gruntjs Grunt生成上的语法错误,gruntjs,yeoman,yeoman-generator,Gruntjs,Yeoman,Yeoman Generator,如果我的代码绝对正确,为什么会出现这个错误?Grunt正在提示错误: c:\xampp\htdocs\yeoman\ci test\Grunt ^正在加载“Gruntfile.js”任务…错误 >>SyntaxError:生成时出现意外标记

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

c:\xampp\htdocs\yeoman\ci test\Grunt <%if(不包括){%> ^正在加载“Gruntfile.js”任务…错误 >>SyntaxError:生成时出现意外标记<

代码:

grunt.registerTask('serve'[
“更少”,
“快车”,
"开放",,
“imagemin”,
“注意”
]);
是lodash模板的开始和结束语句:Grunt在配置中使用这些模板

模板只是字符串,这意味着它们必须包装在
'
中,并使用
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);

在默认服务器设置下,我怀疑您的
gruntfile.js
是否可以编译
,因为它只是一个纯文本JavaScript文件。感谢Jamie,我该怎么做才能创建if-else语句?我是一名PHP开发人员,但我非常确定您需要在asp文件中以某种方式生成此文件。在此之前,asp处理器不会触及该文件重新将其发送到客户端,因此ASP无法运行。我收到一个错误,includeLess未定义,但includeLess在我的索引中。js为什么它看不到该变量?变量
includeLess
需要在GrunFile中。JavaScript只能访问范围内的变量。另一个选项是将其切换为
if(grunt.option)('include-less'))任务。取消移位('less'))
当您使用以下选项运行grunt时:
grunt-service--include less
它将预先完成less任务。谢谢kyle修复了它。最后一件事是,如果我的index.js中有一个includeLess变量,我如何将它传递到我的grunt.js?这是一个yeoman生成器,我正在做。您可以使用
exports.includeLess=includeLess
导出它,然后在GrunFile中需要它:
var includeLess=require('./index.js').includeLess;
虽然你的index.js文件和Grunfile不应该真的相互交谈,但我不知道你的index.js文件的用途。
var tasks = ['express', 'open', 'imagemin', 'watch'];
if (includeLess) tasks.unshift('less'); // add less to the beginning of array
grunt.registerTask('serve', tasks);