dynamic更新Gruntconfiguration字段

我在单独的目录中有几个项目,并希望以相同的方式构build它们。 我想从任务中定义项目名称(作为参数)。 Grunt任务将使用此项目path作为根path。 但我有几个子文件夹,不想手动更新,我只是想更新项目。 有这个机会吗?

grunt.initConfig({ paths : { project : null, projectStylesheets : '<%= paths.project %>/stylesheets', // ... } }); grunt.registerTask('server', function(project) { // -> project = 'some_name' var paths = grunt.config.get('paths'); paths.project = project; grunt.config.set('paths', paths); // -> { project: 'some_name', projectAssets: 'stylesheets' } }); 

我想在他的configuration外使用JS函数,但不知道这是最好的做法。

尝试使用registermultitask – http://gruntjs.com/api/grunt.task#grunt.task.registermultitask

 grunt.initConfig({ projectName1 : { projectStylesheets: 'path_to_stylesheets1', }, projectName2 : { projectStylesheets: 'path_to_stylesheets2', } }) grunt.registerMultiTask('server', function() { var path = grunt.data.projectStylesheets; //operations with stylesheets }); For build use grunt server:projectName1 grunt server:projectName2