Grunt Uglify - Ignore Specific Files/Folders
Asked Answered
P

2

7

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
    }
},
Pyotr answered 16/1, 2014 at 15:34 Comment(4)
You better divide your scripts into two folders. Use uglify on one and concat on the other. It much simpler and everyone is doing that.Bonnee
I was trying to stay away from having to do that since there are a lot of developers under me that won't understand, but if that's the only way I'll use it as a last resort.Pyotr
Lets say that tomorrow your developers add another library. But hey it's not excluded and crash their build. I think this "complicated idea" of dividing assets will be simpler to everyone, and not too hard to explain too.Bonnee
I agree with @IlanFrumer on this one. I think it will be more clear and easy for other devs to understand (even those not familiar with Grunt).Quianaquibble
H
7

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.

Hermann answered 16/1, 2014 at 16:25 Comment(1)
This didn't work for me. Still includes the sub-folder.Zenithal
Z
1

The above answer didn't work for me because that is (as far as I can tell) looking for a sub-sub folder, not a sub-folder.

This is what worked for me:

'!ie/**'
Zenithal answered 2/10, 2014 at 12:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.