shennan
shennan

Reputation: 11676

Stop Grunt Contrib Uglify from removing unused Javascript

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.

Upvotes: 2

Views: 2568

Answers (1)

Pete TNT
Pete TNT

Reputation: 8403

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

Upvotes: 4

Related Questions