[英]Dynamically update Grunt config fields
I have few projects in separate directories and want to build them in the same way. 我在单独的目录中有很少的项目,并希望以相同的方式构建它们。 I want to define project name from task (as param).
我想从task定义项目名称(作为param)。 Grunt tasks will use this project path as root path.
Grunt任务将使用此项目路径作为根路径。 But I have several subfolders and do not want to update it manually I just want to update the project.
但我有几个子文件夹,不想手动更新它我只想更新项目。 There is any chance to do that?
有机会这样做吗?
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' }
});
I was thinking about using JS functions outside he config but not sure is this the best practice. 我正在考虑在配置之外使用JS函数,但不确定这是最佳实践。
Try use registermultitask - http://gruntjs.com/api/grunt.task#grunt.task.registermultitask 尝试使用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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.