Stop Grunt Contrib Uglify from removing unused Javascript

2.5k views Asked by At

There is a function within my Javascript source file that I need to keep within my distribution for posterity (specifically for a sniffer to sniff out some information). It is not being called, but it needs to stay.

The Grunt task, grunt-contrib-uglify is removing this method because it is uncalled in my application.

How can I utilize the compression provided by grunt-contrib-uglify, without removing any code that is deemed unusable by this Grunt library?

Thanks.

1

There are 1 answers

0
Pete TNT On BEST ANSWER

Set options: unused to false

grunt.initConfig({
  uglify: {
    options: {
      compress: {
        unused: false
      }
    },
    my_target: {
      files: {
        'dest/output.min.js': ['src/input.js']
      }
    }
  }
});

Source: UglifyJS global definitions documentation

unused : true, // drop unused variables/functions