2017-04-26 57 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