Integrating Jscrambler with Gulp

Last updated: 16 September 2024

Framework versions tested: 4.0.2 ● 5

Introduction

Gulp is a platform-agnostic toolkit that can be used to automate time-consuming tasks in a development workflow.

The purpose of this document is to describe the steps in integrating Jscrambler with Gulp. We have a plugin tailor-made for this scenario.

If you haven't used Gulp before, be sure to check out the Quick Start guide, as it explains how to install Gulp, and create a Gulpfile.

Integrating Jscrambler with Gulp

If you haven't tried Jscrambler out before reading this tutorial, please consider reading the Getting Started Guide, which will walk you through the steps on how to protect your application. This will make this section easier to grasp. It will also teach you how to configure Jscrambler and use a custom configuration.

First, you are going to need to install our plugin made specifically for integrating with Gulp:

npm install gulp-jscrambler --save-dev

In order to start using gulp-jscrambler you will need to add a new task to your project gulpfile.js. This task will be responsible for protecting your application with Jscrambler.

Here's an example of how Jscrambler task should look like:

const gulp = require('gulp');
const jscrambler = require('gulp-jscrambler');

function enable(filesSrc) {
  if (filesSrc.length === 0) {
    return false;
  }

  return true;
}

gulp.task('default', function (done) {
  gulp
    .src('app/**/*.js')
    .pipe(jscrambler({
      keys: {
        accessKey: '<ACCESS_KEY_HERE>',
        secretKey: '<SECRET_KEY_HERE>'
      },
      applicationId: '<APP_ID_HERE>',
      params: [
        {
          name: 'whitespaceRemoval'
        },
        {
          name: 'stringSplitting'
        }
      ]
    }))
    .pipe(gulp.dest('dist/'))
    .on('end', done);
});

Note that accessKey, secretKey and applicationId need to be replace with your own values. To get yours, as well as to customize your own configuration, you may want to use the Jscrambler Web application and download a JSON configuration file there.

You can change .src and .pipe(gulp.dest('dist/')) to match your project's requirements.

Next, make sure that your build process is using Gulp in package.json:

"scripts": {
  "build": "gulp"
},

Once this is done, whenever you build your application, the Jscrambler task will also be executed, and your code will be protected.

Known Problems

There are no known problems integrating Jscrambler with Gulp.