2017-04-26 56 views
0

我gruntfile迄今創建覆蓋`options`但使用任務級別的子任務`src`

uglify: { 
    src: [ 
     ... 
    ], 
    dest: 'js/application.min.js', 
    options: { 
     'compress': {}, 
     'reserveDOMCache': true, 
     'enclose': undefined, 
     'exportAll': false, 
     'expression': false, 
     'preserveComments': false, 
     'report': 'min', 
     'sourceMap': false, 
     'sourceMapIn': undefined, 
     'sourceMapIncludeSources': false, 
     'sourceMapName': undefined, 
     'wrap': undefined 
    }, 
    development: { 
     options: { 
      'beautify': false, 
      'mangle': true 
     } 
    }, 
    production: { 
     options: { 
      'beautify': true, 
      'mangle': false 
     } 
    } 
} 

然而,當我運行任務uglify:development它將與No files created.

回答

1

據我所知,這個迴應不可能。您需要爲每個目標明確定義一個src。

你可以聲明一個變量的配置之外,並把它添加到每個目標:

var mySources = ['file1.txt', 'file2.txt']; //declared outside config 

development: { 
    src: mySources, //add variable to each target 

或者你可以聲明配置中的變量:

mySourcesInside: ['file1.txt'], //declared within config 

    development: { 
     src: '<%= mySourcesInside%>', //reference variable in each target 

或者,你可以使用類似grunt-override-config​​並聲明一個uglify目標並覆蓋選項。

+1

我能夠適應你的解決方案,以我想用'src的方式工作:'<%= uglify.src%>'' – stackoverfloweth