Grunt plugin that obfuscates your JavaScript using the javascript-obfuscator library.
npm install grunt-contrib-obfuscator-4mergeSourceMap to merge generated source maps with existing ones
shell
npm install grunt-contrib-obfuscator-4 --save-dev
npm install javascript-obfuscator --save-dev
`
Notice that you should install manually javascript-obfuscator. This makes it easier to have a newer version of the obfuscator library if needed.
Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
`js
grunt.loadNpmTasks('grunt-contrib-obfuscator-4');
`
Obfuscator task
_Run this task with the grunt obfuscator command._
Task targets, files and options may be specified according to the grunt Configuring tasks guide.
Options
See the options on the obfuscator repo.
NEW: sourceMap is also supported now.
In addition to the obfuscator options, you can also use:
#### mergeSourceMap
Type: Bool
Default: false
If set to true, and if sourceMap option is enabled, the generated source map will be merged with any existing source map found in the input file.
_NOTE: There's a check to avoid marging a sourceMap from a previous run, but if an input file changes, that check would be negative and it would merge with the previous sourceMap, so better always meake surce to clean the output on start!._
#### baseIdentifiersPrefix
Type: String
Default: '_'
This string will be used as a prefix for the identifiersPrefix values. It must not be numeric. The identifiersPrefix will be set to 'baseIdentifiersPrefix' + n where 'n' is an auto-incrementing number.
#### banner
Type: String
Default: ''
This string will be prepended to the obfuscated output. Template strings (e.g. <%= config.value %> will be expanded automatically.
Usage examples
#### Default options
This configuration will obfuscate the input files using the default options.
`javascript
obfuscator: {
options: {
// global options for the obfuscator
},
task1: {
options: {
// options for each sub task
},
files: {
'dest/output.js': [
'src/js/file1.js',
'src/js/file2.js'
]
}
}
}
`
This configuration will obfuscate the input files in a destination folder by keeping the original names and directories
`javascript
obfuscator: {
options: {
// global options for the obfuscator
},
task1: {
options: {
// options for each sub task
},
files: {
'dest/': [ // the files and their directories will be created in this folder
'src/js/file1.js',
'src/js/folder/file2.js'
]
}
}
}
`
#### Debug protection and banner
Here you code will be protected against debugging and locked to the domain www.example.com.
`javascript
obfuscator: {
options: {
banner: '// obfuscated with grunt-contrib-obfuscator.\n',
debugProtection: true,
debugProtectionInterval: true,
domainLock: ['www.example.com']
},
task1: {
options: {
// options for each sub task
},
files: {
'dest/output.js': [
'src/js/file1.js',
'src/js/file2.js'
]
}
}
}
``