Grunt JavaScript Obfuscator

1.2.0 · maintenance · verified Sun Apr 19

grunt-javascript-obfuscator is a Grunt plugin designed to integrate the powerful `javascript-obfuscator` library into Grunt-based build workflows. It allows developers to automate the process of obfuscating JavaScript source files, enhancing code protection and intellectual property concealment. The current stable version is 1.2.0, released in August 2019, indicating a very slow release cadence; it effectively acts as a wrapper around the core `javascript-obfuscator` library. Key differentiators include its ease of integration with existing Grunt setups and direct exposure of all `javascript-obfuscator` options, enabling fine-grained control over the obfuscation process. It requires Grunt `>=0.4.5` and `javascript-obfuscator >=0.7.2` as peer dependencies, meaning users must install both the plugin and the underlying obfuscation library separately.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates how to set up `grunt-javascript-obfuscator` to obfuscate a single JavaScript file, `src/input.js`, into `dist/obfuscated.js` using a comprehensive set of obfuscation options and source map generation. It includes the necessary `npm install` command, a sample `input.js`, and a `Gruntfile.js` for configuration.

npm install grunt grunt-cli grunt-javascript-obfuscator javascript-obfuscator --save-dev

// src/input.js
(function(){
    var sensitiveData = 'this is a secret value';
    function performCalculation(a, b) {
        return a * b;
    }
    console.log("Result: ", performCalculation(5, 10));
    if (process.env.NODE_ENV === 'production') {
        console.log(sensitiveData);
    }
})();

// Gruntfile.js
module.exports = function(grunt) {
  grunt.initConfig({
    javascript_obfuscator: {
      options: {
        compact: true,
        controlFlowFlattening: true,
        deadCodeInjection: true,
        debugProtection: true,
        debugProtectionInterval: true,
        disableConsoleOutput: true,
        identifierNamesGenerator: 'hexadecimal',
        log: false,
        renameProperties: false,
        selfDefending: true,
        simplify: true,
        splitStrings: true,
        stringArray: true,
        stringArrayEncoding: ['base64'],
        stringArrayThreshold: 0.75,
        transformObjectKeys: true,
        unicodeEscapeSequence: false,
        sourceMap: true // Added in v1.2.0
      },
      dist: {
        files: {
          'dist/obfuscated.js': ['src/input.js']
        }
      }
    }
  });

  grunt.loadNpmTasks('grunt-javascript-obfuscator');

  grunt.registerTask('default', ['javascript_obfuscator']);
};

view raw JSON →