Skip to content

Commit 6f024c1

Browse files
author
Pavel Dranichnikov
committed
Implemented source maps support. Options object is now optional.
1 parent 9635061 commit 6f024c1

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,23 @@ var gulp = require('gulp'),
1717

1818

1919
gulp.src('file.js')
20-
.pipe(javascriptObfuscator({}))
20+
.pipe(javascriptObfuscator())
2121
.pipe(gulp.dest('dist'));
2222
```
2323

24+
2425
## Options
2526

2627
[Pass any options available in the obfuscator](https://github.com/javascript-obfuscator/javascript-obfuscator#javascript-obfuscator-options).
2728

28-
**Please note:** Source maps output is not supported yet. Pull requests are welcome!
29+
```javascript
30+
gulp.src('file.js')
31+
.pipe(javascriptObfuscator({
32+
compact:true
33+
sourceMap: true
34+
}))
35+
.pipe(gulp.dest('dist'));
36+
```
37+
38+
Using **sourceMap** option with value set to **true** will also output a _.map_ file to Gulp stream.
2939

index.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ var through = require('through2'),
44
PluginError = gutil.PluginError;
55

66
module.exports = function gulpJavaScriptObfuscator(options) {
7+
if(!options) {
8+
options = {}
9+
}
10+
711
return through.obj(function (file, enc, cb) {
812
var obfuscationResult;
913
if (file.isNull()) {
@@ -14,7 +18,16 @@ module.exports = function gulpJavaScriptObfuscator(options) {
1418
try {
1519
obfuscationResult = JavaScriptObfuscator.obfuscate(String(file.contents), options);
1620
file.contents = new Buffer(obfuscationResult.getObfuscatedCode());
17-
cb(null, file);
21+
this.push(file);
22+
if(options.sourceMap && options.sourceMapMode !== 'inline') {
23+
this.push(new gutil.File({
24+
cwd: file.cwd,
25+
base: file.base,
26+
path: file.path + '.map',
27+
contents: new Buffer(obfuscationResult.getSourceMap())
28+
}))
29+
}
30+
cb();
1831
}
1932
catch (err) {
2033
throw new PluginError('gulp-javascript-obfuscator', err);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "gulp-javascript-obfuscator",
3-
"version": "1.0.0",
3+
"version": "1.1.0",
44
"description": "Gulp plugin for javascript-obfuscator Node.JS package.",
55
"homepage": "http://github.com/wain-pc/gulp-javascript-obfuscator",
66
"repository": {

0 commit comments

Comments
 (0)