Registry / devops / grunt-javascript-obfuscator

grunt-javascript-obfuscator

JSON →
library1.2.0jsnpmunverified

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.

npm install grunt-javascript-obfuscator
INSTALL
IMPORT
SIG · GRUNT-JAVASCRIPT-O
G
grunt-javascript-obfuscator
devopsjavascriptv1.2.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

grunt.loadNpmTasks
grunt.loadNpmTasks('grunt-javascript-obfuscator');
import { javascriptObfuscator } from 'grunt-javascript-obfuscator';
Grunt plugins are loaded via `loadNpmTasks` in the Gruntfile, not traditional ES modules or CommonJS imports for the task itself.
javascript_obfuscator task configuration
grunt.initConfig({ javascript_obfuscator: { ... } });
grunt.registerTask('obfuscate', ['javascript_obfuscator']);
The task is configured within `grunt.initConfig` under the `javascript_obfuscator` key. `registerTask` is for creating aliases or combining tasks.
Task Options
options: { debugProtection: true, debugProtectionInterval: true }
Options for the obfuscation process are passed directly to the underlying `javascript-obfuscator` library. Refer to `javascript-obfuscator`'s documentation for available options.

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']); };
Debug
Known issues
gotchaThe package's peer dependency for Grunt (`>=0.4.5`) is very old. While it might work with newer Grunt versions, compatibility issues with modern Grunt features or Node.js versions are possible.
fix
Ensure your Grunt CLI and Grunt library versions are compatible with older plugins. Consider testing thoroughly or migrating to a more actively maintained build tool if encountering issues.
affects: >=1.0.0
breakingOptions passed to `grunt-javascript-obfuscator` are directly forwarded to `javascript-obfuscator`. The underlying `javascript-obfuscator` library has undergone many changes and additions since this plugin's last release (v1.2.0 in 2019). Options might have changed names, been deprecated, or introduced new behaviors.
fix
Always consult the latest documentation for `javascript-obfuscator` to ensure that the options you are using are current and behave as expected. Test your obfuscated code thoroughly with each configuration change.
affects: >=1.0.0
gotchaJavaScript obfuscation, while increasing difficulty, does not provide encryption or absolute security for your code. It primarily deters casual inspection and makes reverse-engineering more complex.
fix
Do not rely on obfuscation as a sole security measure for sensitive logic or data. Combine it with server-side validation, API key protection, and other security best practices where true security is required.
affects: *
gotchaSource maps were introduced in v1.2.0, but generating source maps for highly obfuscated code can still be challenging. Debugging obfuscated code, even with source maps, is significantly harder than debugging original code.
fix
Ensure you are on v1.2.0 or higher to use source map generation. Always generate and retain original source code for debugging purposes and only deploy obfuscated versions to production.
affects: <1.2.0
Errors
Common errors & fixes
Warning: Task "javascript_obfuscator" not found. Use --force to continue.
The Grunt plugin `grunt-javascript-obfuscator` has not been loaded in your Gruntfile.
fix
Add `grunt.loadNpmTasks('grunt-javascript-obfuscator');` to your `Gruntfile.js`.
Fatal error: Peer dependency 'javascript-obfuscator@>=0.7.2' not met. Please install 'javascript-obfuscator@>=0.7.2' manually.
The required peer dependency `javascript-obfuscator` is not installed or its version does not meet the specified requirement.
fix
Run `npm install javascript-obfuscator --save-dev` to install the core obfuscator library alongside the Grunt plugin.
Warning: grunt-javascript-obfuscator: `files` or `src` is required.
The `javascript_obfuscator` task is missing the `files` or `src` configuration to specify which JavaScript files should be obfuscated.
fix
Configure your task target with either a `files` object (e.g., `files: { 'dest.js': ['src1.js', 'src2.js'] }`) or a `src` array (e.g., `src: ['src/*.js']`).
Upgrade
Version history
1.2.0latest on npm
Audit
Dependencies
gruntrequiredRequired peer dependency for running Grunt tasks; this package is a Grunt plugin.
javascript-obfuscatorrequiredThe core library that performs JavaScript obfuscation; this package is a wrapper for it.
Agent activity
4 hits · last 30 days
node
4
Resources
grunt-javascript-obfuscator — npm install grunt-javascript-obfuscator · libregistry