我按照grunt.option页面上的说明在Gruntfile中为不同的环境/目标创建不同的配置,例如开发、暂存和生产。然而,在这样做后,我发现我的任务默默地失败了。
我把这个问题简化为一个非常简单的例子。以下Gruntfile无法构建该文件:
module.exports = function (grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
less: {
dev: {
options: {
compress: true
},
build: {
src: ['src/css/test.less'],
dest: 'build/css/test.css'
}
}
}
});
grunt.loadNpmTasks('grunt-contrib-less');
grunt.registerTask('default', ['less:dev']);
};我的终端的输出如下:
$ grunt
Running "less:dev" (less) task
Done, without errors.但是,如果我使用以下Gruntfile,构建输出将如预期的那样:
module.exports = function (grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
less: {
options: {
compress: true
},
build: {
src: ['src/css/test.less'],
dest: 'build/css/test.css'
}
}
});
grunt.loadNpmTasks('grunt-contrib-less');
grunt.registerTask('default', ['less']);
};此Gruntfile的终端输出反映构建的文件:
$ grunt
Running "less:build" (less) task
File build/css/test.css created.
Done, without errors.我在第一个Gruntfile里做错了什么?关于这个task:target大会,我错过了什么?
发布于 2013-09-25 07:54:46
您的第一个Gruntfile -如果您想要每个目标选项,您需要指定files对象。所以你的代码应该是这样的:
less: {
dev: {
files: {
"build/css/test.css": "src/css/test.less"
}
},
production: {
options: {
compress: true
},
files: {
"build/css/test.css": "src/css/test.less"
}
},
}基本上,在您的第一个Gruntfile中,build是一个未知对象。您的目标名为dev,而grunt-contrib-less没有一个名为build的选项,因此Grunt不知道在哪里编写文件。您的第二个Gruntfile可以工作,因为您将选项设置为全局选项。如果需要每个目标选项,请使用上述代码。
https://stackoverflow.com/questions/18998856
复制相似问题