Skip to content

Commit

Permalink
Upgrade to uglify-js 3.0.4. (#472)
Browse files Browse the repository at this point in the history
Upgrade to uglify-js 3.0.4
  • Loading branch information
alexlamsl authored and XhmikosR committed May 12, 2017
1 parent f3086c1 commit ccd7ad0
Show file tree
Hide file tree
Showing 38 changed files with 275 additions and 446 deletions.
122 changes: 63 additions & 59 deletions Gruntfile.js
Expand Up @@ -70,7 +70,7 @@ module.exports = function(grunt) {
},
options: {
mangle: {
except: ['argumentC']
reserved: ['argumentC']
}
}
},
Expand All @@ -83,20 +83,6 @@ module.exports = function(grunt) {
footer: '\n// This is a footer.'
}
},
enclose: {
files: {
'tmp/enclose.js': ['test/fixtures/src/simple.js']
},
options: {
beautify: true,
compress: false,
enclose: {
'window.argA': 'paramA',
'window.argB': 'paramB'
},
mangle: false
}
},
multifile: {
files: {
'tmp/multifile.js': ['test/fixtures/src/simple.js', 'test/fixtures/src/comments.js']
Expand All @@ -110,15 +96,19 @@ module.exports = function(grunt) {
dest: 'tmp/comments.js',
options: {
mangle: false,
preserveComments: 'some'
output: {
comments: 'some'
}
}
},
commentsWithImportant: {
src: 'test/fixtures/src/comments.js',
dest: 'tmp/commentsWithImportant.js',
options: {
mangle: false,
preserveComments: /^!|@preserve|@license|@cc_on/i
output: {
comments: /^!|@preserve|@license|@cc_on/i
}
}
},
wrap: {
Expand All @@ -134,31 +124,26 @@ module.exports = function(grunt) {
dest: 'tmp/maxLineLen.js',
options: {
mangle: false,
maxLineLen: 100
output: {
max_line_len: 100
}
}
},
ASCIIOnly: {
src: 'test/fixtures/src/localization.js',
dest: 'tmp/asciionly.js',
options: {
mangle: false,
ASCIIOnly: true
output: {
ascii_only: true
}
}
},
screwIE8: {
src: 'test/fixtures/src/screwIE8.js',
dest: 'tmp/screwIE8.js',
options: {
screwIE8: false
}
},
exportAll: {
src: 'test/fixtures/src/simple.js',
dest: 'tmp/exportAll.js',
options: {
mangle: false,
wrap: 'testExport',
exportAll: true
ie8: true
}
},
sourcemap_basic: {
Expand Down Expand Up @@ -188,16 +173,18 @@ module.exports = function(grunt) {
src: 'test/fixtures/src/simple.js',
dest: 'tmp/sourcemap_customRoot.js',
options: {
sourceMap: true,
sourceMapRoot: 'https://github.com/RReverser/grunt-contrib-uglify/tree/master/tmp'
sourceMap: {
root: '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: {
url: 'http://www.test.com/test/sourcemap_customUrl.js.map'
}
}
},
sourcemap_functionName: {
Expand Down Expand Up @@ -227,7 +214,7 @@ module.exports = function(grunt) {
options: {
sourceMap: true,
sourceMapName: function(dest) {
return dest+'.fn.map';
return dest + '.fn.map';
}
}
},
Expand All @@ -238,40 +225,45 @@ module.exports = function(grunt) {
options: {
mangle: false,
banner: '// Hello World\n',
sourceMap: true,
sourceMap: {
includeSources: false
},
sourceMapIn: function() {
return 'test/fixtures/src/simple2.map';
},
sourceMapIncludeSources: false
}
}
},
sourcemap_sources: {
files: {
'tmp/sourcemap_sources.js': ['test/fixtures/src/simple.js']
},
options: {
sourceMap: true,
sourceMapIncludeSources: true
sourceMap: {
includeSources: true
}
}
},
sourcemapin_sources: {
files: {
'tmp/sourcemapin_sources.js': ['test/fixtures/src/simple2.js']
},
options: {
sourceMap: true,
sourceMap: {
includeSources: true
},
sourceMapIn: function() {
return 'test/fixtures/src/simple2.map';
},
sourceMapIncludeSources: true
}
}
},
expression_json: {
files: {
'tmp/expression.json': ['test/fixtures/src/simple.json']
},
options: {
expression: true,
parse: {
expression: true
},
mangle: false,
compress: false
}
Expand All @@ -281,7 +273,9 @@ module.exports = function(grunt) {
'tmp/expression.js': ['test/fixtures/src/expression.js']
},
options: {
expression: true,
parse: {
expression: true
},
mangle: false,
compress: false
}
Expand All @@ -291,7 +285,9 @@ module.exports = function(grunt) {
'tmp/mangleprops.js': ['test/fixtures/src/mangleprops.js']
},
options: {
mangleProperties: true
mangle: {
properties: true
}
}
},
mangleprops_withExcept: {
Expand All @@ -300,9 +296,9 @@ module.exports = function(grunt) {
},
options: {
mangle: {
except: ['dontMangleMeVariable']
},
mangleProperties: true
reserved: ['dontMangleMeVariable'],
properties: true
}
}
},
mangleprops_withExceptionsFiles: {
Expand All @@ -311,9 +307,9 @@ module.exports = function(grunt) {
},
options: {
mangle: {
toplevel: true
toplevel: true,
properties: true
},
mangleProperties: true,
exceptionsFiles: ['test/fixtures/src/exceptionsfile1.json', 'test/fixtures/src/exceptionsfile2.json']
}
},
Expand All @@ -324,9 +320,9 @@ module.exports = function(grunt) {
options: {
mangle: {
toplevel: true,
except: ['dontMangleMeVariable']
reserved: ['dontMangleMeVariable'],
properties: true
},
mangleProperties: true,
exceptionsFiles: ['test/fixtures/src/exceptionsfile1.json', 'test/fixtures/src/exceptionsfile2.json']
}
},
Expand All @@ -337,9 +333,9 @@ module.exports = function(grunt) {
},
options: {
mangle: {
toplevel: true
toplevel: true,
properties: true
},
mangleProperties: true,
nameCache: 'tmp/uglify_name_cache.json'
}
},
Expand All @@ -348,8 +344,10 @@ module.exports = function(grunt) {
'tmp/mangleprops_withRegex.js': ['test/fixtures/src/mangleprops_withRegex.js']
},
options: {
mangleProperties: {
regex: /^[^#].*/
mangle: {
properties: {
regex: /^[^#].*/
}
}
}
},
Expand All @@ -358,23 +356,29 @@ module.exports = function(grunt) {
'tmp/quotes_single.js': ['test/fixtures/src/quotes.js']
},
options: {
quoteStyle: 1
output: {
quote_style: 1
}
}
},
quotes_double: {
files: {
'tmp/quotes_double.js': ['test/fixtures/src/quotes.js']
},
options: {
quoteStyle: 2
output: {
quote_style: 2
}
}
},
quotes_original: {
files: {
'tmp/quotes_original.js': ['test/fixtures/src/quotes.js']
},
options: {
quoteStyle: 3
output: {
quote_style: 3
}
}
},
mangle_isNotObject: {
Expand Down
32 changes: 16 additions & 16 deletions docs/uglify-examples.md
Expand Up @@ -39,15 +39,15 @@ grunt.initConfig({

## Reserved identifiers

You can specify identifiers to leave untouched with an `except` array in the `mangle` options.
You can specify identifiers to leave untouched with an `reserved` array in the `mangle` options.

```js
// Project configuration.
grunt.initConfig({
uglify: {
options: {
mangle: {
except: ['jQuery', 'Backbone']
reserved: ['jQuery', 'Backbone']
}
},
my_target: {
Expand Down Expand Up @@ -85,7 +85,7 @@ grunt.initConfig({

## Advanced source maps

Set the `sourceMapIncludeSources` option to `true` to embed your sources directly into the map. To include
Set the `sourceMap.includeSources` option to `true` to embed your sources directly into the map. To include
a source map from a previous compilation pass it as the value of the `sourceMapIn` option.

```js
Expand All @@ -94,8 +94,9 @@ grunt.initConfig({
uglify: {
my_target: {
options: {
sourceMap: true,
sourceMapIncludeSources: true,
sourceMap: {
includeSources: true
},
sourceMapIn: 'example/coffeescript-sourcemap.js', // input sourcemap from a previous compilation
},
files: {
Expand All @@ -106,7 +107,7 @@ grunt.initConfig({
});
```

Refer to the [UglifyJS SourceMap Documentation](http://lisperator.net/uglifyjs/codegen#source-map) for more information.
Refer to the [UglifyJS SourceMap Documentation](https://github.com/mishoo/UglifyJS2#source-map-options) for more information.

## Turn off console warnings

Expand Down Expand Up @@ -134,11 +135,9 @@ grunt.initConfig({
## Beautify

Specify `beautify: true` to beautify your code for debugging/troubleshooting purposes.
Pass an object to manually configure any other output options passed directly to `UglifyJS.OutputStream()`.

See [UglifyJS Codegen documentation](http://lisperator.net/uglifyjs/codegen) for more information.
Pass an object to manually configure any other output options.

_Note that manual configuration will require you to explicitly set `beautify: true` if you want traditional, beautified output._
See [UglifyJS documentation](https://github.com/mishoo/UglifyJS2#beautifier-options) for more information.

```js
// Project configuration.
Expand All @@ -155,8 +154,7 @@ grunt.initConfig({
my_advanced_target: {
options: {
beautify: {
width: 80,
beautify: true
width: 80
}
},
files: {
Expand Down Expand Up @@ -193,9 +191,9 @@ grunt.initConfig({

## Conditional compilation

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).
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.

See [UglifyJS global definitions documentation](http://lisperator.net/uglifyjs/compress#global-defs) for more information.
See [UglifyJS global definitions documentation](https://github.com/mishoo/UglifyJS2#conditional-compilation) for more information.

```js
// Project configuration.
Expand Down Expand Up @@ -250,7 +248,7 @@ uglify: {
dev: {
options: {
mangle: {
except: ['jQuery']
reserved: ['jQuery']
}
},
files: [{
Expand Down Expand Up @@ -280,7 +278,9 @@ on the format of the exception file format please see the [UglifyJS docs](https:
grunt.initConfig({
uglify: {
options: {
mangleProperties: true,
mangle: {
properties: true
},
reserveDOMCache: true,
exceptionsFiles: [ 'myExceptionsFile.json' ]
},
Expand Down

0 comments on commit ccd7ad0

Please sign in to comment.