grunt-contrib-uglify
Advanced tools
Comparing version 0.1.0 to 0.1.1-rc5
@@ -10,3 +10,3 @@ # Options | ||
Type: `Boolean` `Object` | ||
Default: `{}` | ||
Default: `{}` | ||
@@ -17,3 +17,3 @@ Turn on or off mangling with default options. If an `Object` is specified, it is passed directly to `ast.mangle_names()` *and* `ast.compute_char_frequency()` (mimicking command line behavior). | ||
Type: `Boolean` `Object` | ||
Default: `{}` | ||
Default: `{}` | ||
@@ -24,3 +24,3 @@ Turn on or off source compression with default options. If an `Object` is specified, it is passed as options to `UglifyJS.Compressor()`. | ||
Type: `Boolean` `Object` | ||
Default: `false` | ||
Default: `false` | ||
@@ -31,3 +31,3 @@ Turns on beautification of the generated source code. An `Object` will be merged and passed with the options sent to `UglifyJS.OutputStream()`. | ||
Type: `String` | ||
Default: `undefined` | ||
Default: `undefined` | ||
@@ -38,3 +38,3 @@ Specify the location to output the source map. | ||
Type: `String` | ||
Default: `undefined` | ||
Default: `undefined` | ||
@@ -45,3 +45,3 @@ The location where your source files can be found. | ||
Type: `String` | ||
Default: `undefined` | ||
Default: `undefined` | ||
@@ -52,10 +52,30 @@ The location of an input source map from an earlier compilation, e.g. from CoffeeScript. | ||
Type: `String` | ||
Default: `undefined` | ||
Default: `undefined` | ||
The location of your sourcemap. Defaults to the location you use for sourceMap, override if you need finer control | ||
## sourceMapPrefix | ||
Type: `Number` | ||
Default: `undefined` | ||
The number of directories to drop from the path prefix when declaring files in the source map. | ||
## wrap | ||
Type: `String` | ||
Default: `undefined` | ||
Wrap all of the code in a closure, an easy way to make sure nothing is leaking. | ||
For variables that need to be public `exports` and `global` variables are made available. | ||
The value of wrap is the global variable exports will be available as. | ||
## exportAll | ||
Type: `Boolean` | ||
Default: `false` | ||
When using `wrap` this will make all global functions and variables available via the export variable. | ||
## preserveComments | ||
Type: `Boolean` `String` `Function` | ||
Default: `undefined` | ||
Options: `false` `'all'` `'some'` | ||
Options: `false` `'all'` `'some'` | ||
@@ -71,3 +91,3 @@ Turn on preservation of comments. | ||
Type: `String` | ||
Default: empty string | ||
Default: empty string | ||
@@ -78,2 +98,3 @@ This string will be prepended to the beginning of the minified output. It is processed using [grunt.template.process][], using the default options. | ||
[grunt.template.process]: https://github.com/gruntjs/grunt/blob/devel/docs/api_template.md#grunttemplateprocess | ||
[grunt.template.process]: https://github.com/gruntjs/grunt/wiki/grunt.template#wiki-grunt-template-process | ||
@@ -106,2 +106,28 @@ /* | ||
} | ||
}, | ||
wrap: { | ||
src: 'test/fixtures/src/simple.js', | ||
dest: 'tmp/wrap.js', | ||
options: { | ||
mangle: false, | ||
wrap: 'testExport' | ||
} | ||
}, | ||
exportAll: { | ||
src: 'test/fixtures/src/simple.js', | ||
dest: 'tmp/exportAll.js', | ||
options: { | ||
mangle: false, | ||
wrap: 'testExport', | ||
exportAll: true | ||
} | ||
}, | ||
sourcemap_prefix: { | ||
files: { | ||
'/dev/null': ['test/fixtures/src/simple.js'] | ||
}, | ||
options: { | ||
sourceMap: 'tmp/sourcemap_prefix', | ||
sourceMapPrefix: 3 | ||
} | ||
} | ||
@@ -108,0 +134,0 @@ }, |
{ | ||
"name": "grunt-contrib-uglify", | ||
"description": "Minify files with UglifyJS.", | ||
"version": "0.1.0", | ||
"version": "0.1.1rc5", | ||
"homepage": "https://github.com/gruntjs/grunt-contrib-uglify", | ||
@@ -35,9 +35,9 @@ "author": { | ||
"devDependencies": { | ||
"grunt-contrib-clean": "~0.4.0a", | ||
"grunt-contrib-jshint": "~0.1.0", | ||
"grunt-contrib-nodeunit": "~0.1.1", | ||
"grunt-contrib-internal": "~0.1.1", | ||
"grunt": "~0.4.0" | ||
"grunt-contrib-jshint": "~0.1.1rc5", | ||
"grunt-contrib-nodeunit": "~0.1.2rc5", | ||
"grunt-contrib-clean": "~0.4.0rc5", | ||
"grunt-contrib-internal": "*", | ||
"grunt": "~0.4.0rc5" | ||
}, | ||
"keywords": [] | ||
} |
@@ -34,3 +34,3 @@ # grunt-contrib-uglify [![Build Status](https://secure.travis-ci.org/gruntjs/grunt-contrib-uglify.png?branch=master)](http://travis-ci.org/gruntjs/grunt-contrib-uglify) | ||
Type: `Boolean` `Object` | ||
Default: `{}` | ||
Default: `{}` | ||
@@ -41,3 +41,3 @@ Turn on or off mangling with default options. If an `Object` is specified, it is passed directly to `ast.mangle_names()` *and* `ast.compute_char_frequency()` (mimicking command line behavior). | ||
Type: `Boolean` `Object` | ||
Default: `{}` | ||
Default: `{}` | ||
@@ -48,3 +48,3 @@ Turn on or off source compression with default options. If an `Object` is specified, it is passed as options to `UglifyJS.Compressor()`. | ||
Type: `Boolean` `Object` | ||
Default: `false` | ||
Default: `false` | ||
@@ -55,3 +55,3 @@ Turns on beautification of the generated source code. An `Object` will be merged and passed with the options sent to `UglifyJS.OutputStream()`. | ||
Type: `String` | ||
Default: `undefined` | ||
Default: `undefined` | ||
@@ -62,3 +62,3 @@ Specify the location to output the source map. | ||
Type: `String` | ||
Default: `undefined` | ||
Default: `undefined` | ||
@@ -69,3 +69,3 @@ The location where your source files can be found. | ||
Type: `String` | ||
Default: `undefined` | ||
Default: `undefined` | ||
@@ -76,10 +76,30 @@ The location of an input source map from an earlier compilation, e.g. from CoffeeScript. | ||
Type: `String` | ||
Default: `undefined` | ||
Default: `undefined` | ||
The location of your sourcemap. Defaults to the location you use for sourceMap, override if you need finer control | ||
#### sourceMapPrefix | ||
Type: `Number` | ||
Default: `undefined` | ||
The number of directories to drop from the path prefix when declaring files in the source map. | ||
#### wrap | ||
Type: `String` | ||
Default: `undefined` | ||
Wrap all of the code in a closure, an easy way to make sure nothing is leaking. | ||
For variables that need to be public `exports` and `global` variables are made available. | ||
The value of wrap is the global variable exports will be available as. | ||
#### exportAll | ||
Type: `Boolean` | ||
Default: `false` | ||
When using `wrap` this will make all global functions and variables available via the export variable. | ||
#### preserveComments | ||
Type: `Boolean` `String` `Function` | ||
Default: `undefined` | ||
Options: `false` `'all'` `'some'` | ||
Options: `false` `'all'` `'some'` | ||
@@ -95,3 +115,3 @@ Turn on preservation of comments. | ||
Type: `String` | ||
Default: empty string | ||
Default: empty string | ||
@@ -102,4 +122,5 @@ This string will be prepended to the beginning of the minified output. It is processed using [grunt.template.process][], using the default options. | ||
[grunt.template.process]: https://github.com/gruntjs/grunt/blob/devel/docs/api_template.md#grunttemplateprocess | ||
[grunt.template.process]: https://github.com/gruntjs/grunt/wiki/grunt.template#wiki-grunt-template-process | ||
### Usage examples | ||
@@ -276,2 +297,3 @@ | ||
* 2013-01-08 v0.1.1rc5 Updating to work with grunt v0.4.0rc5. Switching back to this.files api. | ||
* 2012-11-27 v0.1.0 Work in progress, not yet officially released. | ||
@@ -283,2 +305,2 @@ | ||
*This file was generated on Thu Dec 13 2012 15:42:18.* | ||
*This file was generated on Wed Jan 09 2013 14:12:29.* |
@@ -35,2 +35,5 @@ /* | ||
var code = grunt.file.read(file); | ||
if (typeof options.sourceMapPrefix !== 'undefined') { | ||
file = file.replace(/^\/+/, "").split(/\/+/).slice(options.sourceMapPrefix).join("/"); | ||
} | ||
totalCode += code; | ||
@@ -43,2 +46,7 @@ topLevel = UglifyJS.parse(code, { | ||
// Wrap code in a common js wrapper. | ||
if (options.wrap) { | ||
topLevel = topLevel.wrap_commonjs(options.wrap, options.exportAll); | ||
} | ||
// Need to call this before we mangle or compress, | ||
@@ -45,0 +53,0 @@ // and call after any compression or ast altering |
@@ -27,47 +27,48 @@ /* | ||
}); | ||
var result; | ||
// The source files to be processed. The "nonull" option is used | ||
// to retain invalid files/patterns so they can be warned about. | ||
var files = grunt.file.expand({nonull: true}, this.file.srcRaw); | ||
// Process banner. | ||
var banner = grunt.template.process(options.banner); | ||
// Warn if a source file/pattern was invalid. | ||
var invalidSrc = files.some(function(filepath) { | ||
if (!grunt.file.exists(filepath)) { | ||
grunt.log.error('Source file "' + filepath + '" not found.'); | ||
return true; | ||
// Iterate over all src-dest file pairs. | ||
this.files.forEach(function(f) { | ||
var src = f.src.filter(function(filepath) { | ||
// Warn on and remove invalid source files (if nonull was set). | ||
if (!grunt.file.exists(filepath)) { | ||
grunt.log.warn('Source file "' + filepath + '" not found.'); | ||
return false; | ||
} else { | ||
return true; | ||
} | ||
}); | ||
// Minify files, warn and fail on error. | ||
var result; | ||
try { | ||
result = uglify.minify(src, f.dest, options); | ||
} catch (e) { | ||
var err = new Error('Uglification failed.'); | ||
err.origError = e; | ||
grunt.fail.warn(err); | ||
} | ||
}); | ||
if (invalidSrc) { return false; } | ||
// Minify files, warn and fail on error. | ||
try { | ||
result = uglify.minify(files, this.file.dest, options); | ||
} catch(e) { | ||
grunt.log.error(e); | ||
grunt.fail.warn('uglification failed!'); | ||
} | ||
// Concat banner + minified source. | ||
var output = banner + result.min; | ||
// Concat banner + minified source. | ||
var banner = grunt.template.process(options.banner); | ||
var output = banner + result.min; | ||
// Write the destination file. | ||
grunt.file.write(f.dest, output); | ||
// Write the destination file. | ||
grunt.file.write(this.file.dest, output); | ||
// Write source map | ||
if (options.sourceMap) { | ||
grunt.file.write(options.sourceMap, result.sourceMap); | ||
grunt.log.writeln('Source Map "' + options.sourceMap + '" created.'); | ||
} | ||
// Write source map | ||
if (options.sourceMap) { | ||
grunt.file.write(options.sourceMap, result.sourceMap); | ||
} | ||
// Print a success message. | ||
grunt.log.writeln('File "' + f.dest + '" created.'); | ||
// Print a success message. | ||
grunt.log.writeln('File "' + this.file.dest + '" created.'); | ||
// ...and report some size information. | ||
minlib.info(result.min, result.max); | ||
// Fail task if any errors were logged. | ||
if (this.errorCount > 0) { return false; } | ||
// ...and report some size information. | ||
minlib.info(result.min, result.max); | ||
}); | ||
}); | ||
}; |
@@ -20,2 +20,5 @@ 'use strict'; | ||
'multifile.js', | ||
'wrap.js', | ||
'exportAll.js', | ||
'sourcemap_prefix' | ||
]; | ||
@@ -22,0 +25,0 @@ |
Sorry, the diff of this file is not supported yet
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
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
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
39654
48
489
296
1