Last updated: 16 September 2024
Framework versions tested: 1.6.1
Grunt is an open source Javascript task runner.
The purpose of this document is to describe the steps in integrating Jscrambler with Grunt. We have a plugin tailor-made for this scenario.
If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins.
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 Grunt:
npm install grunt-jscrambler --save-dev
Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
grunt.loadNpmTasks('grunt-jscrambler');
Then, we will be setting up the Jscrambler Grunt task, where your selected files will be protected by Jscrambler. In your project's Gruntfile, add a section named jscrambler to the data object passed into grunt.initConfig().
grunt.initConfig({
jscrambler: {
main: {
options: {
keys: {
accessKey: '<ACCESS_KEY_HERE>',
secretKey: '<SECRET_KEY_HERE>'
},
applicationId: '<APP_ID_HERE>',
params: [
{
name: 'whitespaceRemoval'
},
{
name: 'charToTernaryOperator'
}
]
},
files: [
{expand: true, src: ['foo.js', 'bar.js'], dest: 'dist/'},
],
// (Optional) Retrieve the protection Id
successCallback(protectionId) {
// console.log('Protection Id: ', protectionId);
}
}
},
});
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.
There are no known problems integrating Jscrambler with Grunt.