这是vs2013 web项目中我的gruntjs文件的片段。我所看到的是在initconfig中添加最后一行来加载设置,停止显示VS2013 Task Runner Explorer中的任务。一旦注释掉该行,Task Runner Explorer就会枚举我的任务。 Task Runner ExplorerI的输出窗口中没有错误。
我可以使用grunt cli运行我的gruntfile.js。
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
target: grunt.config.get('target'),
settings: grunt.file.readJSON('config/' + grunt.option('target') + '.json'), //problematic line
karma: {
unit: {
configFile: 'karma.conf.js'
}
},
答案 0 :(得分:0)
我遇到了grunt.file.readJSON的问题,我通过给我的选项一个自调用函数来解决它,该函数检查文件是否存在。类似的东西:
settings: function () {
if (grunt.file.exists('config/' + grunt.option('target') + '.json')) {
return grunt.file.readJSON('config/' + grunt.option('target') + '.json')
}
return '';
}()