Gruntjs 如何为多个目标动态重用grunt复制任务?
我不想在dest属性中添加目的地,而是想使其成为动态的,这样我可以在从命令行运行任务或从其他任务运行任务时分配目的地。这样,无论何时调用任务,我都可以将文件复制到我想要的任何文件夹中Gruntjs 如何为多个目标动态重用grunt复制任务?,gruntjs,grunt-contrib-copy,Gruntjs,Grunt Contrib Copy,我不想在dest属性中添加目的地,而是想使其成为动态的,这样我可以在从命令行运行任务或从其他任务运行任务时分配目的地。这样,无论何时调用任务,我都可以将文件复制到我想要的任何文件夹中 copy: { nightlyBuild: { files: [{ expand: true, cwd: '../', src: ['index.html'],
copy: {
nightlyBuild: {
files: [{
expand: true,
cwd: '../',
src: ['index.html'],
dest: 'destinations'
}]
}
},
我假设我需要使用grunt.option和grunt.config,但似乎无法正确使用。我有多个脚本,我希望以类似的方式重复使用。我认为您的思路是正确的。这应该会有所帮助
copy: {
nightlyBuild: {
files: [{
expand: true,
cwd: '../',
src: ['index.html'],
dest: '<%= dest %>',
}]
}
},
grunt.task.registerTask('copyTo', 'copy into a specific destination', function(dest) {
if (arguments.length === 0) {
grunt.log.writeln(this.name + ", missing destination");
} else {
grunt.log.writeln(this.name + " to " + dest);
grunt.config.set('dest', dest);
grunt.task.run([
'copy:nightlyBuild'
]);
}
});
复制:{
夜间建造:{
档案:[{
是的,
cwd:“../”,
src:['index.html'],
目标:'',
}]
}
},
grunt.task.registerTask('copyTo','copy into a specific destination',function(dest){
if(arguments.length==0){
grunt.log.writeln(this.name+“,缺少目标”);
}否则{
grunt.log.writeln(this.name+“到”+dest);
grunt.config.set('dest',dest);
grunt.task.run([
“复制:夜间构建”
]);
}
});
然后您可以这样调用该任务:
grunt copyTo:mydestination
我认为您的思路是正确的。这应该会有所帮助
copy: {
nightlyBuild: {
files: [{
expand: true,
cwd: '../',
src: ['index.html'],
dest: '<%= dest %>',
}]
}
},
grunt.task.registerTask('copyTo', 'copy into a specific destination', function(dest) {
if (arguments.length === 0) {
grunt.log.writeln(this.name + ", missing destination");
} else {
grunt.log.writeln(this.name + " to " + dest);
grunt.config.set('dest', dest);
grunt.task.run([
'copy:nightlyBuild'
]);
}
});
复制:{
夜间建造:{
档案:[{
是的,
cwd:“../”,
src:['index.html'],
目标:'',
}]
}
},
grunt.task.registerTask('copyTo','copy into a specific destination',function(dest){
if(arguments.length==0){
grunt.log.writeln(this.name+“,缺少目标”);
}否则{
grunt.log.writeln(this.name+“到”+dest);
grunt.config.set('dest',dest);
grunt.task.run([
“复制:夜间构建”
]);
}
});
然后您可以这样调用此任务:
grunt copyTo:mydestination
非常感谢,此配置和选项交互说明了很多内容,并将帮助我完成所有脚本。非常感谢,此配置和选项交互说明了很多内容,并将帮助我完成所有脚本。