gruntjsgrunt-contrib-uglify

Create subtasks that override `options` but use task level `src`


My gruntfile thus far

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
        }
    }
}

However when I run the task uglify:development it will respond with No files created.


Solution

  • As far as I know this is not possible. You need to explicitly define a src for each target.

    You could declare a variable outside of the config and add it to each target:

    var mySources = ['file1.txt', 'file2.txt']; //declared outside config
    
     development: {
         src: mySources, //add variable to each target
    

    Or you can declare a variable inside the config:

    mySourcesInside: ['file1.txt'], //declared within config
    
      development: {
           src: '<%= mySourcesInside%>', //reference variable in each target
    

    Alternatively you could use something like grunt-override-config https://github.com/masakura/grunt-override-config and declare just one uglify target and overrides for the options.