gulp-uglify
Advanced tools
Comparing version 0.1.0 to 0.2.0
60
index.js
@@ -1,18 +0,56 @@ | ||
var es = require('event-stream'), | ||
uglify = require('uglify-js'); | ||
'use strict'; | ||
var through = require('through2'), | ||
uglify = require('uglify-js'), | ||
merge = require('deepmerge'), | ||
Vinyl = require('vinyl'); | ||
module.exports = function(opt) { | ||
'use strict'; | ||
opt = opt || {}; | ||
opt.fromString = true; | ||
function minify(file, encoding, callback) { | ||
/*jshint validthis:true */ | ||
var options = merge(opt || {}, { | ||
fromString: true, | ||
output: {} | ||
}); | ||
return es.map(function (file, callback) { | ||
var mangled, | ||
map; | ||
if (options.outSourceMap === true) { | ||
options.outSourceMap = file.relative + '.map'; | ||
} | ||
if (options.preserveComments === 'all') { | ||
options.output.comments = true; | ||
} else if (options.preserveComments === 'some') { | ||
// preserve comments with directives or that start with a bang (!) | ||
options.output.comments = /^!|@preserve|@license|@cc_on/i; | ||
} else if (typeof options.preserveComments === 'function') { | ||
options.output.comments = options.preserveComments; | ||
} | ||
try { | ||
file.contents = new Buffer(uglify.minify(String(file.contents), opt).code); | ||
} catch(e) { | ||
console.warn('Error caught from uglify: ' + e.message + '. Returning unminified code'); | ||
mangled = uglify.minify(String(file.contents), options); | ||
file.contents = new Buffer(mangled.code); | ||
this.push(file); | ||
} catch (e) { | ||
console.warn('Error caught from uglify: ' + e.message + ' in ' + file.path + '. Returning unminifed code'); | ||
this.push(file); | ||
return callback(); | ||
} | ||
callback(null, file); | ||
}); | ||
if (options.outSourceMap) { | ||
map = new Vinyl({ | ||
cwd: file.cwd, | ||
base: file.base, | ||
path: file.path + '.map', | ||
contents: new Buffer(mangled.map) | ||
}); | ||
this.push(map); | ||
} | ||
callback(); | ||
} | ||
return through.obj(minify); | ||
}; |
{ | ||
"name": "gulp-uglify", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "Minify files with UglifyJS.", | ||
@@ -12,9 +12,10 @@ "keywords": [ | ||
"dependencies": { | ||
"event-stream": "~3.0.15", | ||
"uglify-js": "~2.4.6", | ||
"clone": "~0.1.9" | ||
"through2": "~0.4.0", | ||
"vinyl": "~0.2.3", | ||
"deepmerge": "~0.2.7" | ||
}, | ||
"main": "index.js", | ||
"engines": { | ||
"node": ">= 0.6" | ||
"node": ">= 0.9" | ||
}, | ||
@@ -27,4 +28,8 @@ "scripts": { | ||
"chai": "~1.8.1", | ||
"gulp": "~2.6.0" | ||
} | ||
"gulp": ">= 3.4.0 <3.6.0" | ||
}, | ||
"peerDependencies": { | ||
"gulp": ">= 3.4.0 <3.6.0" | ||
}, | ||
"license": "MIT" | ||
} |
@@ -15,3 +15,3 @@ [![Build Status](https://travis-ci.org/terinjokes/gulp-uglify.png?branch=master)](https://travis-ci.org/terinjokes/gulp-uglify) | ||
<td>Node Version</td> | ||
<td>≥ 0.6</td> | ||
<td>≥ 0.9</td> | ||
</tr> | ||
@@ -26,31 +26,58 @@ </table> | ||
gulp.task('compress', function() { | ||
gulp.files('./lib/*.js') | ||
.pipe(uglify()) | ||
.pipe(gulp.folder('./dist/')) | ||
gulp.src('lib/*.js') | ||
.pipe(uglify({outSourceMaps: true)) | ||
.pipe(gulp.dest('dist')) | ||
}); | ||
``` | ||
## LICENSE | ||
## Options | ||
(MIT License) | ||
- `mangle` | ||
> Copyright (c) 2013 Terin Stock <terinjokes@gmail.com> | ||
> | ||
> Permission is hereby granted, free of charge, to any person obtaining | ||
> a copy of this software and associated documentation files (the | ||
> "Software"), to deal in the Software without restriction, including | ||
> without limitation the rights to use, copy, modify, merge, publish, | ||
> distribute, sublicense, and/or sell copies of the Software, and to | ||
> permit persons to whom the Software is furnished to do so, subject to | ||
> the following conditions: | ||
> | ||
> The above copyright notice and this permission notice shall be | ||
> included in all copies or substantial portions of the Software. | ||
> | ||
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
> EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
> MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
> NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
> LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
> OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
> WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
Pass `false` to skip mangling names. | ||
- `output` | ||
Pass an object if you wish to specify additional [output | ||
options](http://lisperator.net/uglifyjs/codegen). The defaults are | ||
optimized for best compression. | ||
- `compress` | ||
Pass an object to specify custom [compressor | ||
options](http://lisperator.net/uglifyjs/compress). Pass `false` to skip | ||
compression completely. | ||
- `preserveComments` | ||
A convenience option for `options.output.comments`. Defaults to preserving no | ||
comments. | ||
- `all` | ||
Preserve all comments in code blocks | ||
- `some` | ||
Preserve comments that start with a bang (`!`) or include a Closure | ||
Compiler directive (`@preserve`, `@license`, `@cc_on`) | ||
- `function` | ||
Specify your own comment preservation function. You will be passed the | ||
current node and the current comment and are expected to return either | ||
`true` or `false`. | ||
You can also pass the `uglify` function any of the options [listed | ||
here](https://github.com/mishoo/UglifyJS2#the-simple-way) to modify | ||
UglifyJS's behavior. | ||
### Source Maps | ||
You can have UglifyJS’s generated source maps emitted on the stream by passing | ||
`true` for the `outSourceMap` option. The file object’s path will be based on | ||
the input file’s, with ‘.map’ appended. | ||
Input source maps are no supported by this plugin at this time. | ||
@@ -1,2 +0,2 @@ | ||
/* | ||
/*! | ||
* Licensed under the MIT license. | ||
@@ -29,2 +29,2 @@ */ | ||
return a; | ||
}()) | ||
}()) |
'use strict'; | ||
/* globals describe, it */ | ||
var gulp = require('gulp'), | ||
expect = require('chai').expect, | ||
uglify = require('../'), | ||
uglifyjs = require('uglify-js'), | ||
es = require('event-stream'), | ||
fs = require('fs'), | ||
path = require('path'); | ||
expect = require('chai').expect, | ||
uglify = require('..'), | ||
uglifyjs = require('uglify-js'), | ||
through = require('through2'), | ||
fs = require('fs'), | ||
path = require('path'); | ||
@@ -17,5 +17,6 @@ describe('gulp-uglify minification', function() { | ||
.pipe(uglify()) | ||
.pipe(es.map(function(file){ | ||
.pipe(through.obj(function(file, encoding, callback) { | ||
var expected = uglifyjs.minify(filename).code; | ||
expect(String(file.contents)).to.equal(expected); | ||
callback(); | ||
done(); | ||
@@ -29,4 +30,5 @@ })); | ||
.pipe(uglify()) | ||
.pipe(es.map(function(file) { | ||
.pipe(through.obj(function(file, encoding, callback) { | ||
expect(file.contents).to.be.an.instanceof(Buffer); | ||
callback(); | ||
done(); | ||
@@ -40,9 +42,39 @@ })); | ||
.pipe(uglify()) | ||
.pipe(es.map(function(file) { | ||
.pipe(through.obj(function(file, encoding, callback) { | ||
var expected = fs.readFileSync(filename, 'utf-8'); | ||
expect(String(file.contents)).to.equal(expected); | ||
callback(); | ||
done(); | ||
})); | ||
}); | ||
it('should dynamically name source map files', function(done) { | ||
var filename = path.join(__dirname, './fixtures/data.js'); | ||
gulp.src(filename) | ||
.pipe(uglify({outSourceMap: true})) | ||
.pipe(through.obj(function(file, encoding, callback) { | ||
var map; | ||
if (/\.map/.test(file.path)) { | ||
map = JSON.parse(file.contents); | ||
expect(file.path).to.equal(filename + '.map'); | ||
expect(map).to.be.an.instanceof(Object); | ||
done(); | ||
} | ||
callback(); | ||
})); | ||
}); | ||
it('should preserve some comments', function(done) { | ||
var filename = path.join(__dirname, './fixtures/data.js'); | ||
gulp.src(filename) | ||
.pipe(uglify({preserveComments: 'some'})) | ||
.pipe(through.obj(function(file, encoding, callback) { | ||
expect(file.contents).to.be.an.instanceof(Buffer); | ||
expect(/MIT/.test(file.contents)).to.be.true; | ||
callback(); | ||
done(); | ||
})); | ||
}); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No License Found
License(Experimental) License information could not be found.
Found 1 instance in 1 package
8260
11
140
82
5
80
+ Addeddeepmerge@~0.2.7
+ Addedthrough2@~0.4.0
+ Addedvinyl@~0.2.3
+ Addedansi-regex@0.2.1(transitive)
+ Addedansi-styles@1.0.01.1.0(transitive)
+ Addedarchy@0.0.2(transitive)
+ Addedarray-find-index@1.0.2(transitive)
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedcamelcase@2.1.1(transitive)
+ Addedcamelcase-keys@2.1.0(transitive)
+ Addedchalk@0.4.00.5.1(transitive)
+ Addedclone-stats@0.0.1(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addedcore-util-is@1.0.3(transitive)
+ Addedcurrently-unhandled@0.4.1(transitive)
+ Addeddateformat@1.0.12(transitive)
+ Addeddeepmerge@0.2.10(transitive)
+ Addeddeprecated@0.0.1(transitive)
+ Addedduplexer2@0.0.2(transitive)
+ Addedend-of-stream@0.1.5(transitive)
+ Addederror-ex@1.3.2(transitive)
+ Addedescape-string-regexp@1.0.5(transitive)
+ Addedextend@1.2.1(transitive)
+ Addedfind-index@0.1.1(transitive)
+ Addedfind-up@1.1.2(transitive)
+ Addedfindup-sync@0.1.3(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedgaze@0.5.2(transitive)
+ Addedget-stdin@4.0.1(transitive)
+ Addedglob@3.1.213.2.114.5.3(transitive)
+ Addedglob-stream@3.1.18(transitive)
+ Addedglob-watcher@0.0.6(transitive)
+ Addedglob2base@0.0.12(transitive)
+ Addedglobule@0.1.0(transitive)
+ Addedgraceful-fs@1.2.32.0.34.2.11(transitive)
+ Addedgulp@3.5.6(transitive)
+ Addedgulp-util@2.2.20(transitive)
+ Addedhas-ansi@0.1.0(transitive)
+ Addedhas-color@0.1.7(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedhosted-git-info@2.8.9(transitive)
+ Addedindent-string@2.1.0(transitive)
+ Addedinflight@1.0.6(transitive)
+ Addedinherits@1.0.22.0.4(transitive)
+ Addedis-arrayish@0.2.1(transitive)
+ Addedis-core-module@2.15.1(transitive)
+ Addedis-finite@1.1.0(transitive)
+ Addedis-utf8@0.2.1(transitive)
+ Addedisarray@0.0.1(transitive)
+ Addedliftoff@0.9.8(transitive)
+ Addedload-json-file@1.1.0(transitive)
+ Addedlodash@1.0.22.4.2(transitive)
+ Addedlodash._escapehtmlchar@2.4.1(transitive)
+ Addedlodash._escapestringchar@2.4.1(transitive)
+ Addedlodash._htmlescapes@2.4.1(transitive)
+ Addedlodash._isnative@2.4.1(transitive)
+ Addedlodash._objecttypes@2.4.1(transitive)
+ Addedlodash._reinterpolate@2.4.1(transitive)
+ Addedlodash._reunescapedhtml@2.4.1(transitive)
+ Addedlodash._shimkeys@2.4.1(transitive)
+ Addedlodash.defaults@2.4.1(transitive)
+ Addedlodash.escape@2.4.1(transitive)
+ Addedlodash.isobject@2.4.1(transitive)
+ Addedlodash.keys@2.4.1(transitive)
+ Addedlodash.template@2.4.1(transitive)
+ Addedlodash.templatesettings@2.4.1(transitive)
+ Addedlodash.values@2.4.1(transitive)
+ Addedloud-rejection@1.6.0(transitive)
+ Addedlru-cache@2.7.3(transitive)
+ Addedmap-obj@1.0.1(transitive)
+ Addedmap-stream@0.1.0(transitive)
+ Addedmeow@3.7.0(transitive)
+ Addedminimatch@0.2.140.3.02.0.10(transitive)
+ Addedminimist@0.0.100.2.41.2.8(transitive)
+ Addedmkdirp@0.3.5(transitive)
+ Addedmultipipe@0.1.2(transitive)
+ Addednormalize-package-data@2.5.0(transitive)
+ Addedobject-assign@4.1.1(transitive)
+ Addedobject-keys@0.4.0(transitive)
+ Addedonce@1.3.3(transitive)
+ Addedorchestrator@0.3.8(transitive)
+ Addedordered-read-streams@0.1.0(transitive)
+ Addedparse-json@2.2.0(transitive)
+ Addedpath-exists@2.1.0(transitive)
+ Addedpath-parse@1.0.7(transitive)
+ Addedpath-type@1.1.0(transitive)
+ Addedpify@2.3.0(transitive)
+ Addedpinkie@2.0.4(transitive)
+ Addedpinkie-promise@2.0.1(transitive)
+ Addedpretty-hrtime@0.2.2(transitive)
+ Addedread-pkg@1.1.0(transitive)
+ Addedread-pkg-up@1.0.1(transitive)
+ Addedreadable-stream@1.0.341.1.14(transitive)
+ Addedredent@1.0.0(transitive)
+ Addedrepeating@2.0.1(transitive)
+ Addedresolve@0.6.31.22.8(transitive)
+ Addedsemver@2.3.2(transitive)
+ Addedsequencify@0.0.7(transitive)
+ Addedsigmund@1.0.1(transitive)
+ Addedsignal-exit@3.0.7(transitive)
+ Addedspdx-correct@3.2.0(transitive)
+ Addedspdx-exceptions@2.5.0(transitive)
+ Addedspdx-expression-parse@3.0.1(transitive)
+ Addedspdx-license-ids@3.0.20(transitive)
+ Addedstream-consume@0.1.1(transitive)
+ Addedstring_decoder@0.10.31(transitive)
+ Addedstrip-ansi@0.1.10.3.0(transitive)
+ Addedstrip-bom@2.0.0(transitive)
+ Addedstrip-indent@1.0.1(transitive)
+ Addedsupports-color@0.2.0(transitive)
+ Addedsupports-preserve-symlinks-flag@1.0.0(transitive)
+ Addedthrough2@0.4.20.5.10.6.5(transitive)
+ Addedtrim-newlines@1.0.0(transitive)
+ Addedunique-stream@1.0.0(transitive)
+ Addedvalidate-npm-package-license@3.0.4(transitive)
+ Addedvinyl@0.2.3(transitive)
+ Addedvinyl-fs@0.1.4(transitive)
+ Addedwrappy@1.0.2(transitive)
+ Addedxtend@2.1.23.0.04.0.2(transitive)
- Removedclone@~0.1.9
- Removedevent-stream@~3.0.15
- Removedclone@0.1.19(transitive)
- Removedduplexer@0.1.2(transitive)
- Removedevent-stream@3.0.20(transitive)
- Removedfrom@0.1.7(transitive)
- Removedmap-stream@0.0.7(transitive)
- Removedpause-stream@0.0.11(transitive)
- Removedsplit@0.2.10(transitive)
- Removedstream-combiner@0.0.4(transitive)
- Removedthrough@2.3.8(transitive)