Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conditional Compilation using UglifyJS + GruntJS

I'm using grunt-bbb for a JavaScript project I'm working on. I'd love to use conditional compilation using grunt's support for UglifyJS, but I cannot seem to get it to work. I'm trying to pass a defines option to uglify task, but it doesn't seem to be working.

My grunt.js file looks like:

module.exports = function (grunt) {
    grunt.initConfig({

        // ... config options ...

        uglify: {
            "mangle": {
                "defines": {"DEBUG": false}
            }
        },

        // ... more configs ...

    });

    // ... custom tasks ...

    grunt.registerTask("release", "default min mincss");
};

I've tried to add an except property to the mangle object as well, and that doesn't seem to work either (it still mangles the file...) UglifyJS is obviously being run, but it doesn't seem like it's getting the options passed in. I've dug through the code as well and when I console.log(grunt.config('uglify')); I get

{ mangle: { defines: { DEBUG: false } } }

which looks correct to me...

Any thoughts???

like image 438
Jesse Fulton Avatar asked Apr 17 '26 10:04

Jesse Fulton


1 Answers

This is what currently works for me:

uglify: {
  options: {
    compress: {
      global_defs: {
        APP_DEBUG: false
      }
    }
  }
}

putting it in the compress option works, in this case it will set APP_DEBUG=false I got this fix from here: https://github.com/gruntjs/grunt-contrib-uglify/issues/12

like image 77
nate Avatar answered Apr 20 '26 00:04

nate