2014-12-29 119 views
0

我可以設置文件的多個陣列目標:Grunt任務目標數組?

task:{ 
    target:{ 
     files:[ 
      { 
       expand:true, 
       cwd:'client/', 
       dest:'server/', 
       src:[ 
        'scripts/**/*.js', 
        'styles/**/*.css', 
        'images/**' 
       ] 
      }, 
      { 
       expand:true, 
       cwd:'client/assets/', 
       src:'**/*', 
       dest:'server/' 
      } 
     ] 
    } 
} 

現在我想要做同樣的目標。

像這樣:

task:{ 
    server:[ 
     { 
      options:{ 
       … 
      }, 
      files:{ 
       … 
      } 
     }, 
     { 
      options:{ 
       … 
      }, 
      files:{ 
       … 
      } 
     } 
    ] 
} 

但是,這並不與繁重的工作:

Warning: Object #<Object> has no method 'indexOf' Use --force to continue. 

我該怎麼辦呢?

現在我用這個方案做相同的:

task:{ 
    server_<subtask_one>:{ 
     options:{ 
      … 
     }, 
     files:{ 
      … 
     } 
    }, 
    server_<subtask_second>:{ 
     options:{ 
      … 
     }, 
     files:{ 
      … 
     } 
    } 
} 

但它不是很方便的重複任務前綴,每個子任務,然後將它們發射到單獨的行這樣的:

'dataSeparator:<target>_<subtask_one>', 
'dataSeparator:<target>_<subtask_second>', 

回答

0

除非你想寫一個自定義任務,否則這是你唯一的選擇。但是大多數任務都允許您指定在任務級別的options塊,這樣你至少可以節省自己的一些重複:

task:{ 
    options:{ 
     // options common to all tasks 
    }, 
    server_<subtask_one>:{ 
     options:{ 
      // override options if necessary 
     }, 
     files:{ 
      // custom for this target 
     } 
    }, 
    server_<subtask_second>:{ 
     options:{ 
      // override options if necessary 
     }, 
     files:{ 
      // custom for this target 
     } 
    } 
} 

正如我所說的,你也許可以編寫自定義任務來動態重置grunt config options每個目標,但這是混亂的,我不會建議它...甚至不知道它會正常工作。

grunt.registerTask('mutli-task', 'Compile options and pass to task', function() { 

    grunt.config.set('task.server_<subtask_one>.some_setting', 'value'); 
    // ... 
    grunt.task.run('task'); 

    // Now do it again, but with different settings... maybe in a loop? 
}); 
+0

我已經知道了。感謝您的澄清。 –