Grunt Uglify - Ignore Specific Files/Folders

StephenRios picture StephenRios · Jan 16, 2014 · Viewed 8.4k times · Source

When running uglify, I need to make it ignore certain files and folders, but still scan the entire folder structure recursively.

I have a concat task that concats together all of my plugins and makes them a single file. I need to make sure uglify ignores these files and doesn't operate on them because I don't want them in the destination directory since concat already handled that for me.

I tried adding the files and folders to my src array with preceding !'s, but it still operates on them.

Below is what I am trying to use, but it's not working:

uglify: {
    options: {
        banner: '/*! <%= grunt.template.today("mm-dd-yyyy h:MM:ss TT") %> */\n'
    },
    files: {
        src: [
                 '!ie'
                ,'!polyfills'
                ,'!vendor'
                ,'!iecompat.js'
                ,'**/*.js'
             ],
        dest: 'app/scripts',
        cwd: 'sources/scripts',
        ext: ".js",
        flatten: false,
        expand: true
    }
},

Answer

Mangled Deutz picture Mangled Deutz · Jan 16, 2014

Ilan Frumer suggestion is probably a good one.

Now, about your specific question, your patterns certainly need to be adapted as follow:

Example:

 '!**/ie/*'

will ignore any file in a folder named "ie" anywhere in your subdirectories (which is likely what you want, is this correct?)

Same goes for:

 '!**/iecompat.js'

that will ignore a file named iecompat.js anywhere in folders / subfolders.

You should start here to better understand file selection mechanisms in grunt.