Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: gruntjs/grunt-contrib-uglify
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.11.1
Choose a base ref
...
head repository: gruntjs/grunt-contrib-uglify
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v1.0.0
Choose a head ref
  • 13 commits
  • 12 files changed
  • 6 contributors

Commits on Jan 22, 2015

  1. Log @ normal for min/gzip && verbose for none/false

    This is a middle ground approach between no output
    and reporting of compression information.  The
    log facility is controlled via the option report.
    meschbach committed Jan 22, 2015
    Copy the full SHA
    1111f01 View commit details
  2. Copy the full SHA
    bbb742b View commit details

Commits on Feb 20, 2015

  1. Copy the full SHA
    eec87eb View commit details

Commits on Apr 26, 2015

  1. Add 'sourceMapUrl' option

    Added an option to override the calcuated sourceMappingUrl value in the
    minified output
    RyanFrench committed Apr 26, 2015
    Copy the full SHA
    e2da335 View commit details

Commits on Aug 17, 2015

  1. add bare_returns option

    PacciniBruno committed Aug 17, 2015
    Copy the full SHA
    1886bfa View commit details

Commits on Feb 2, 2016

  1. Improving docs for global-defs and --define options

    Joel Denning committed Feb 2, 2016
    Copy the full SHA
    2a08091 View commit details
  2. Merge pull request #390 from joeldenning/define-docs

    Improving docs for global-defs and --define options
    vladikoff committed Feb 2, 2016
    Copy the full SHA
    e2e019d View commit details

Commits on Mar 3, 2016

  1. Copy the full SHA
    f9817e9 View commit details

Commits on Mar 4, 2016

  1. Merge pull request #327 from RyanFrench/master

    Add 'sourceMapUrl' option
    vladikoff committed Mar 4, 2016
    Copy the full SHA
    2c17823 View commit details
  2. Merge pull request #394 from saibotsivad/master

    Use uglify-js ~2.6.2 to fix sourcemap issue
    vladikoff committed Mar 4, 2016
    Copy the full SHA
    5982873 View commit details
  3. Merge pull request #348 from PacciniBruno/master

    add bare_returns option
    vladikoff committed Mar 4, 2016
    Copy the full SHA
    5f6f748 View commit details
  4. Merge pull request #288 from meschbach/master

    Optionally set report verbosity level using report option
    vladikoff committed Mar 4, 2016
    Copy the full SHA
    5107d7d View commit details
  5. v1.0.0

    vladikoff committed Mar 4, 2016
    Copy the full SHA
    a75d773 View commit details
8 changes: 8 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
v1.0.0:
date: 2016-03-04
changes:
- Use uglify-js ~2.6.2 to fix sourcemap issue.
- Improving docs for global-defs and --define options.
- Add 'sourceMapUrl' option.
- add bare_returns option.
- Optionally set report verbosity level using report option.
v0.11.1:
date: 2016-01-29
changes:
8 changes: 8 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -184,6 +184,14 @@ module.exports = function(grunt) {
sourceMapRoot: 'https://github.com/RReverser/grunt-contrib-uglify/tree/master/tmp'
}
},
sourcemap_customUrl: {
src: 'test/fixtures/src/simple.js',
dest: 'tmp/sourcemap_customUrl.js',
options: {
sourceMap: true,
sourceMapUrl: 'http://www.test.com/test/sourcemap_customUrl.js.map'
}
},
sourcemap_functionName: {
src: 'test/fixtures/src/simple.js',
dest: 'tmp/sourcemap_functionName.js',
16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# grunt-contrib-uglify v0.11.1 [![Build Status: Linux](https://travis-ci.org/gruntjs/grunt-contrib-uglify.svg?branch=master)](https://travis-ci.org/gruntjs/grunt-contrib-uglify) [![Build Status: Windows](https://ci.appveyor.com/api/projects/status/ybtf5vbvtenii561/branch/master?svg=true)](https://ci.appveyor.com/project/gruntjs/grunt-contrib-uglify/branch/master)
# grunt-contrib-uglify v1.0.0 [![Build Status: Linux](https://travis-ci.org/gruntjs/grunt-contrib-uglify.svg?branch=master)](https://travis-ci.org/gruntjs/grunt-contrib-uglify) [![Build Status: Windows](https://ci.appveyor.com/api/projects/status/ybtf5vbvtenii561/branch/master?svg=true)](https://ci.appveyor.com/project/gruntjs/grunt-contrib-uglify/branch/master)

> Minify javascript files with UglifyJS
@@ -80,11 +80,12 @@ Default: `false`
Parse a single expression, rather than a program (for parsing JSON)

#### report
Choices: `'min'`, `'gzip'`
Choices: `false, 'none', 'min'`, `'gzip'`
Default: `'min'`

Either report only minification result or report minification and gzip results.
This is useful to see exactly how well clean-css is performing but using `'gzip'` will make the task take 5-10x longer to complete. [Example output](https://github.com/sindresorhus/maxmin#readme).
If false or 'none' is used the report will be generated on the verbose output.

#### sourceMap
Type: `Boolean`
@@ -120,6 +121,12 @@ With this option you can customize root URL that browser will use when looking f

If the sources are not absolute URLs after prepending of the `sourceMapRoot`, the sources are resolved relative to the source map.

#### sourceMapUrl
Type: `String`
Default: `undefined`

Override the calculated value for `sourceMappingURL` in the source map. This is useful if the source map location is not relative to the base path of the minified file, i.e. when using a CDN

###### enclose
Type: `Object`
Default: `undefined`
@@ -415,7 +422,7 @@ grunt.initConfig({

#### Conditional compilation

You can also enable UglifyJS conditional compilation. This is commonly used to remove debug code blocks for production builds.
You can also enable UglifyJS conditional compilation. This is commonly used to remove debug code blocks for production builds. This is equivalent to the command line [`--define` option](https://github.com/mishoo/UglifyJS#use-as-a-code-pre-processor).

See [UglifyJS global definitions documentation](http://lisperator.net/uglifyjs/compress#global-defs) for more information.

@@ -510,6 +517,7 @@ grunt.initConfig({

## Release History

* 2016-03-04   v1.0.0   Use uglify-js ~2.6.2 to fix sourcemap issue. Improving docs for global-defs and --define options. Add 'sourceMapUrl' option. add bare_returns option. Optionally set report verbosity level using report option.
* 2016-01-29   v0.11.1   switch to lodash ^4.0.1 switch to grunt-contrib-clean ^0.7.0 switch to grunt-contrib-jshint ^0.12.0
* 2015-11-20   v0.11.0   switch to uglify ~2.6.0
* 2015-11-12   v0.10.1   switch to uglify ~2.5
@@ -545,4 +553,4 @@ grunt.initConfig({

Task submitted by ["Cowboy" Ben Alman](http://benalman.com)

*This file was generated on Tue Feb 02 2016 11:38:37.*
*This file was generated on Fri Mar 04 2016 12:46:01.*
2 changes: 1 addition & 1 deletion docs/uglify-examples.md
Original file line number Diff line number Diff line change
@@ -193,7 +193,7 @@ grunt.initConfig({

## Conditional compilation

You can also enable UglifyJS conditional compilation. This is commonly used to remove debug code blocks for production builds.
You can also enable UglifyJS conditional compilation. This is commonly used to remove debug code blocks for production builds. This is equivalent to the command line [`--define` option](https://github.com/mishoo/UglifyJS#use-as-a-code-pre-processor).

See [UglifyJS global definitions documentation](http://lisperator.net/uglifyjs/compress#global-defs) for more information.

9 changes: 8 additions & 1 deletion docs/uglify-options.md
Original file line number Diff line number Diff line change
@@ -31,11 +31,12 @@ Default: `false`
Parse a single expression, rather than a program (for parsing JSON)

## report
Choices: `'min'`, `'gzip'`
Choices: `false, 'none', 'min'`, `'gzip'`
Default: `'min'`

Either report only minification result or report minification and gzip results.
This is useful to see exactly how well clean-css is performing but using `'gzip'` will make the task take 5-10x longer to complete. [Example output](https://github.com/sindresorhus/maxmin#readme).
If false or 'none' is used the report will be generated on the verbose output.

## sourceMap
Type: `Boolean`
@@ -71,6 +72,12 @@ With this option you can customize root URL that browser will use when looking f

If the sources are not absolute URLs after prepending of the `sourceMapRoot`, the sources are resolved relative to the source map.

## sourceMapUrl
Type: `String`
Default: `undefined`

Override the calculated value for `sourceMappingURL` in the source map. This is useful if the source map location is not relative to the base path of the minified file, i.e. when using a CDN

#### enclose
Type: `Object`
Default: `undefined`
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "grunt-contrib-uglify",
"description": "Minify javascript files with UglifyJS",
"version": "0.11.1",
"version": "1.0.0",
"author": {
"name": "Grunt Team",
"url": "http://gruntjs.com/"
@@ -19,7 +19,7 @@
"chalk": "^1.0.0",
"lodash": "^4.0.1",
"maxmin": "^2.0.0",
"uglify-js": "~2.6.0",
"uglify-js": "~2.6.2",
"uri-path": "^1.0.0"
},
"devDependencies": {
8 changes: 6 additions & 2 deletions tasks/lib/uglify.js
Original file line number Diff line number Diff line change
@@ -45,6 +45,7 @@ exports.init = function(grunt) {
var sourceMapDir = path.dirname(options.generatedSourceMapName);
var relativePath = path.relative(sourceMapDir, fileDir);
var pathPrefix = relativePath ? relativePath + path.sep : '';
var bare_returns = options.bare_returns || undefined;

// Convert paths to use forward slashes for sourcemap use in the browser
file = uriPath(pathPrefix + basename);
@@ -53,7 +54,8 @@ exports.init = function(grunt) {
topLevel = UglifyJS.parse(code, {
filename: file,
toplevel: topLevel,
expression: options.expression
expression: options.expression,
bare_returns: bare_returns
});
});

@@ -192,7 +194,9 @@ exports.init = function(grunt) {
// Add the source map reference to the end of the file
if (options.sourceMap) {
// Set all paths to forward slashes for use in the browser
min += '\n//# sourceMappingURL=' + uriPath(options.destToSourceMap);
var sourceMappingURL;
sourceMappingURL = options.destToSourceMap.match(/^http[s]?\:\/\//) === null ? uriPath(options.destToSourceMap) : options.destToSourceMap;
min += '\n//# sourceMappingURL=' + sourceMappingURL;
}

var result = {
36 changes: 29 additions & 7 deletions tasks/uglify.js
Original file line number Diff line number Diff line change
@@ -24,6 +24,20 @@ function relativePath(file1, file2) {
return '';
}

function reportFacility( grunt, options ){
var reporter;
switch( options.report ){
case 'none':
reporter = grunt.verbose;
break;
default:
case 'min':
case 'gzip':
reporter = grunt.log;
}
return reporter;
}

// Converts \r\n to \n
function normalizeLf(string) {
return string.replace(/\r\n/g, '\n');
@@ -50,6 +64,7 @@ module.exports = function(grunt) {
screwIE8: false,
quoteStyle: 0
});
var log = reportFacility( grunt, options );

// Process banner.
var banner = normalizeLf(options.banner);
@@ -123,10 +138,16 @@ module.exports = function(grunt) {

// Calculate the path from the dest file to the sourcemap for the
// sourceMappingURL reference
if (options.sourceMap) {
var destToSourceMapPath = relativePath(f.dest, options.generatedSourceMapName);
var sourceMapBasename = path.basename(options.generatedSourceMapName);
options.destToSourceMap = destToSourceMapPath + sourceMapBasename;
// If sourceMapUrl is defined, use this instead
if(options.sourceMap) {
var destToSourceMapPath, sourceMapBasename;
if (!options.sourceMapUrl) {
destToSourceMapPath = relativePath(f.dest, options.generatedSourceMapName);
sourceMapBasename = path.basename(options.generatedSourceMapName);
options.destToSourceMap = destToSourceMapPath + sourceMapBasename;
} else {
options.destToSourceMap = options.sourceMapUrl;
}
}

// Minify files, warn and fail on error.
@@ -161,12 +182,13 @@ module.exports = function(grunt) {
// Write source map
if (options.sourceMap) {
grunt.file.write(options.generatedSourceMapName, result.sourceMap);
grunt.verbose.writeln('File ' + chalk.cyan(options.generatedSourceMapName) + ' created (source map).');
log.writeln('File ' + chalk.cyan(options.generatedSourceMapName) + ' created (source map).');
createdMaps++;
}

grunt.verbose.writeln('File ' + chalk.cyan(f.dest) + ' created: ' +
maxmin(result.max, output, options.report === 'gzip'));
var outputSize = maxmin(result.max, output, options.report === 'gzip');
log.writeln('File ' + chalk.cyan(f.dest) + ' created: ' + outputSize);

createdFiles++;
});

2 changes: 2 additions & 0 deletions test/fixtures/expected/sourcemap_customUrl.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test/fixtures/expected/sourcemapin.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test/fixtures/expected/sourcemapin_sources.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/uglify_test.js
Original file line number Diff line number Diff line change
@@ -32,6 +32,7 @@ exports.contrib_uglify = {
'sourcemap_customName.js',
'sourcemap_customRoot.js',
'sourcemap_customRoot.js.map',
'sourcemap_customUrl.js',
'sourcemap_functionName.js',
'sourcemap_functionName.js.fn.map',
path.join('deep', 'directory', 'location', 'source_map.js.map'),