javascriptgruntjsfrontendgrunt-contrib-uglify

How to prevent grunt uglify to override destination folder


I am trying to setup my grunt file to not to override some folders inside the destination folders, but I couldn't figure out how.

My structure

Basically I have 2 folders:

htdocs_src is the folder we use to develop things, and then we run a watch task that copies all the code to htdocs folder.

My problem

We add some libraries directly on the htdocs folder, so we don't want them to be touched by grunt uglify task... The problem is that it is not happening.

The task is configured this way:

uglify: {
        options : {
            beautify: false,
            report: "min",
            mangle: {
                except: ['jQuery']
            },
            exclude: ['!/ifc-easy-checkout*/**/*', '!/ifc-events*/**/*', '!/ifc-vendors*/**/*'],
            compress: {
                global_defs: {
                  "DEBUG": false
                }/*,
                dead_code: true*/
            }
        },
        target: {
            cwd: '<%= dirs.GENERATED_JS %>',
            src: ['**/*.js'],
            dest: '<%= dirs.GENERATED_JS %>',
            expand: true
        },
    },

where on the exclude property I try to say to the plugin not to override these folders, but it doesn't work.

I am currently using grunt-contrib-uglify 2.0.0

I tried several different solutions, such as changing the exclude property for exceptionsFiles, but then it searched for these folders inside the htdocs_src, since it is not there, it doesn't work (but it isn't what I want, once what I need is to avoid some folders to be overriden inside the destination folder).

Any ideas how to setup this plugin?


Solution

  • Try putting the excluded files in the src and remove the exclude tag

     target: {
                cwd: '<%= dirs.GENERATED_JS %>',
                src: ['**/*.js','!/ifc-easy-checkout*/**/*', '!/ifc-events*/**/*', '!/ifc-vendors*/**/*'],
                dest: '<%= dirs.GENERATED_JS %>',
                expand: true
            },