1

我不想在 dest 属性中添加目的地,而是想让它成为动态的,这样当我从命令行运行任务或从另一个任务运行它时,我可以分配目的地。这样,每当我调用任务时,我都可以将文件复制到我想要的任何文件夹中。

copy: {
        nightlyBuild: {
            files: [{
                expand: true,
                cwd: '../',
                src: ['index.html'],
                dest: 'destinations'
            }]
         }
      },

我假设我需要使用 grunt.option 和 grunt.config 但似乎无法正确使用。我有多个脚本,我想以类似的方式重用它们。

4

1 回答 1

4

我认为你在正确的轨道上。这应该有帮助

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'
    ]);
  }
});

然后,您将像这样调用任务:grunt copyTo:mydestination

于 2015-05-12T01:30:23.280 回答