2014-12-29 6 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

나는 이미 알고 있습니다. 명확성을 가져 주셔서 감사합니다. –