Gulp JavaScript Obfuscator

1.1.6 · maintenance · verified Sun Apr 19

gulp-javascript-obfuscator is a Gulp plugin that integrates the powerful `javascript-obfuscator` library into Gulp build workflows. Currently at version 1.1.6, this package provides a stream-based interface for obfuscating JavaScript files, adding a layer of protection against reverse engineering and making code harder to read. This plugin is typically stable, with its release cadence tied to updates in the underlying `javascript-obfuscator` for feature enhancements and Gulp-specific maintenance. A key differentiator is its seamless integration with `gulp-sourcemaps`, which allows for proper debugging of obfuscated code by automatically generating corresponding source maps. This ensures a robust and maintainable obfuscation process within existing Gulp pipelines and supports chaining with other Gulp plugins like Babel for pre-processing.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to set up a Gulp task to obfuscate JavaScript files, incorporating Babel for transpilation and `gulp-sourcemaps` for generating debug-friendly sourcemaps alongside the obfuscated output.

const gulp = require('gulp');
const javascriptObfuscator = require('gulp-javascript-obfuscator');
const sourcemaps = require('gulp-sourcemaps');
const babel = require('@babel/core'); // Optional: for pre-processing JS
const babelPresetEnv = require('@babel/preset-env'); // Optional: for Babel preset

gulp.task('obfuscate-js', () => {
  return gulp.src('src/**/*.js')
    .pipe(sourcemaps.init()) // Initialize sourcemaps before any transformations
    .pipe(babel({
      presets: [babelPresetEnv]
    })) // Optional: Transpile modern JS to a compatible version
    .pipe(javascriptObfuscator({
      compact: true, // Example option: compact the obfuscated code
      // Other javascript-obfuscator options can go here
      // IMPORTANT: Do NOT set `sourceMap: true` here when using gulp-sourcemaps
    }))
    .pipe(sourcemaps.write('.')) // Write sourcemaps to the same directory as output
    .pipe(gulp.dest('dist')); // Output obfuscated and sourcemap files to 'dist'
});

// To run this task: npx gulp obfuscate-js

view raw JSON →