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 に答える