grunt.jsconfiguration中常见configuration选项的inheritance

人们如何处理Grunt中的多个项目的常见configuration选项。 这些项目将共享一些常见的configuration选项,例如min ,但也有每个项目的私人自定义configuration设置,例如,三个项目中只有一个需要less或有不同的选项。

有没有办法在项目之间共享这种通用configuration,使用inheritance或导入现有文件,还是每个项目都必须定义所有设置?

我所指的项目将驻留在目录层次结构中

 root module1 grunt.js module2 grunt.js module3 grunt.js 

有什么方法可以在root级别提供常见的configuration设置吗?

您可以根据需要轻松地将configuration存储在尽可能多的外部JSON文件中。 grunt.file.readJSON将帮助你在这里。 例如:

 module.exports = function(grunt) { var concatConf = grunt.file.readJSON('../concat-common.json'), minConf = grunt.file.readJSON('../min-common.json'); // do whatever you want with concatConf and minConf here // ... // Project configuration. grunt.initConfig({ pkg: '<json:grunt-sample.jquery.json>', meta: { banner: '/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - ' + '<%= grunt.template.today("yyyy-mm-dd") %>\n' + '<%= pkg.homepage ? "* " + pkg.homepage + "\n" : "" %>' + '* Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>;' + ' Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %> */' }, concat: concatConf, min: minConf // ... }); // Default task. grunt.registerTask('default', 'concat min'); }; 

不要忘记,gruntfile是在Node环境中执行的常规JavaScript文件,configuration选项是常规的JavaScript对象:)