grunt-contrib-uglify-2.0.0/000077500000000000000000000000001274343240600156105ustar00rootroot00000000000000grunt-contrib-uglify-2.0.0/.editorconfig000066400000000000000000000002541274343240600202660ustar00rootroot00000000000000root = true [*] indent_style = space indent_size = 2 end_of_line = lf insert_final_newline = true trim_trailing_whitespace = true [*.md] trim_trailing_whitespace = false grunt-contrib-uglify-2.0.0/.gitattributes000066400000000000000000000000621274343240600205010ustar00rootroot00000000000000* text=auto *.js text eol=lf *.js.map text eol=lf grunt-contrib-uglify-2.0.0/.gitignore000066400000000000000000000000571274343240600176020ustar00rootroot00000000000000node_modules npm-debug.log tmp .idea .DS_Store grunt-contrib-uglify-2.0.0/.jshintrc000066400000000000000000000003211274343240600174310ustar00rootroot00000000000000{ "boss": true, "curly": true, "eqeqeq": true, "eqnull": true, "immed": true, "latedef": true, "newcap": true, "noarg": true, "node": true, "sub": true, "undef": true, "unused": true } grunt-contrib-uglify-2.0.0/.travis.yml000066400000000000000000000002511274343240600177170ustar00rootroot00000000000000sudo: false language: node_js node_js: - "0.10" - "0.12" - "4" - "5" - "6" - "iojs" matrix: fast_finish: true cache: directories: - node_modules grunt-contrib-uglify-2.0.0/AUTHORS000066400000000000000000000001701274343240600166560ustar00rootroot00000000000000"Cowboy" Ben Alman (http://benalman.com) Tyler Kellen (http://goingslowly.com) Jarrod Overson (http://jarrodoverson.com)grunt-contrib-uglify-2.0.0/CHANGELOG000066400000000000000000000100051274343240600170160ustar00rootroot00000000000000v2.0.0: date: 2016-07-19 changes: - Update uglify-js to v2.7.0. `screwIE8` is enabled by default. v1.0.2: date: 2016-07-19 changes: - Update grunt to ^1.0.0. - Fix `beautify` when passed as an object. - Fix docs about `report` values. v1.0.1: date: 2016-03-16 changes: - Downgrade maxmin for Node.js 0.10. v1.0.0: date: 2016-03-04 changes: - Use uglify-js ~2.6.2 to fix sourcemap issue. - Improve 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: - Update lodash to ^4.0.1. - Update grunt-contrib-clean to ^0.7.0. - Update grunt-contrib-jshint to ^0.12.0. v0.11.0: date: 2015-11-20 changes: - Update uglify-js to ~2.6.0. v0.10.1: date: 2015-11-12 changes: - Update uglify-js to ~2.5. v0.10.0: date: 2015-10-27 changes: - Update uglify-js to ^2.5. v0.9.2: date: 2015-08-24 changes: - Update uglify-js to ^2.4.24 v0.9.1: date: 2015-04-07 changes: - More fixes for `mangle` options. v0.9.0: date: 2015-04-07 changes: - Add hook into uglify-js's mangling functionality. v0.8.1: date: 2015-03-30 changes: - Lock uglify-js to 2.4.17 due to breaking changes. v0.8.0: date: 2015-02-19 changes: - Add `screwIE8` option. - Fix issue with explicit `compress` in Node.js 0.12.0. v0.7.0: date: 2014-12-23 changes: - Add `sourceMapRoot` options. - Update readme descriptions. - Remove reference to clean-css. v0.6.0: date: 2014-09-17 changes: - Output fixes. - 'Add `ASCIIOnly` option.' - Other fixes. v0.5.1: date: 2014-07-25 changes: - Update chalk to ^0.5.1. - Output updates. v0.4.0: date: 2014-03-01 changes: - Remove grunt-lib-contrib dependency and add more colors. v0.3.3: date: 2014-02-27 changes: - Remove unnecessary calls to `grunt.template.process`. v0.3.2: date: 2014-01-22 changes: - Fix handling of `sourceMapIncludeSources` option. v0.3.1: date: 2014-01-20 changes: - Fix relative path issue in sourcemaps. v0.3.0: date: 2014-01-16 changes: - Refactor sourcemap support. v0.2.7: date: 2013-11-09 changes: - 'Prepend banner if `sourceMap` option not set, addresses #109.' v0.2.6: date: 2013-11-08 changes: - 'Merge #45, #53, #85 (#105 by way of duping #53).' - Add support for banners in uglified files with sourcemaps. - Update docs. v0.2.5: date: 2013-10-28 changes: - Add warning for banners when using sourcemaps. v0.2.4: date: 2013-09-02 changes: - 'Update sourcemap format via #83.' v0.2.3: date: 2013-06-10 changes: - Add `footer` option. v0.2.2: date: 2013-05-31 changes: - 'Revert #56 due to #58 until [chrome/239660](https://code.google.com/p/chromium/issues/detail?id=239660&q=sourcemappingurl&colspec=ID%20Pri%20M%20Iteration%20ReleaseBlock%20Cr%20Status%20Owner%20Summary%20OS%20Modified) [firefox/870361](https://bugzilla.mozilla.org/show_bug.cgi?id=870361) drop.' v0.2.1: date: 2013-05-22 changes: - 'Update uglify-js to ~2.3.5 #55 #40.' - 'Change `sourcemappingUrl` syntax #56.' - 'Disable sorting of names for consistent mangling #44.' - 'Update docs for `sourceMapRoot` #47 #25.' v0.2.0: date: 2013-03-14 changes: - No longer report gzip results by default. - Support `report` option. v0.1.2: date: 2013-01-30 changes: - Add better error reporting. - Support for dynamic names of multiple sourcemaps. v0.1.1: date: 2013-02-15 changes: - First official release for Grunt 0.4.0. v0.1.1rc6: date: 2013-01-18 changes: - Update grunt/gruntplugin dependencies to rc6. - Change in-development grunt/gruntplugin dependency versions from tilde version ranges to specific versions. v0.1.1rc5: date: 2013-01-09 changes: - Update to work with grunt v0.4.0rc5. - Switch back to `this.files` API. v0.1.0: date: 2012-11-28 changes: - Work in progress, not officially released yet. grunt-contrib-uglify-2.0.0/CONTRIBUTING.md000066400000000000000000000001771274343240600200460ustar00rootroot00000000000000Please see the [Contributing to grunt](http://gruntjs.com/contributing) guide for information on contributing to this project. grunt-contrib-uglify-2.0.0/Gruntfile.js000066400000000000000000000261451274343240600201150ustar00rootroot00000000000000/* * grunt-contrib-uglify * http://gruntjs.com/ * * Copyright (c) 2016 "Cowboy" Ben Alman, contributors * Licensed under the MIT license. */ 'use strict'; module.exports = function(grunt) { // Project configuration. grunt.initConfig({ jshint: { all: [ 'Gruntfile.js', 'tasks/**/*.js', '<%= nodeunit.tests %>' ], options: { jshintrc: '.jshintrc' } }, // Before generating any new files, remove any previously-created files. clean: { tests: ['tmp'] }, // Configuration to be run (and then tested). uglify: { compress: { files: { 'tmp/compress.js': ['test/fixtures/src/simple.js'] }, options: { mangle: false } }, compress_explicit: { files: { 'tmp/compress_explicit.js': ['test/fixtures/src/simple.js'] }, options: { compress: true } }, compress_mangle: { files: { 'tmp/compress_mangle.js': ['test/fixtures/src/simple.js'] } }, compress_mangle_banner: { files: { 'tmp/compress_mangle_banner.js': ['test/fixtures/src/simple.js'] }, options: { banner: '// banner without sourcemap\n' } }, no_src: { files: { 'tmp/compress_mangle.js': [] } }, compress_mangle_except: { files: { 'tmp/compress_mangle_except.js': ['test/fixtures/src/simple.js'] }, options: { mangle: { except: ['argumentC'] } } }, compress_mangle_beautify: { files: { 'tmp/compress_mangle_beautify.js': ['test/fixtures/src/simple.js'] }, options: { beautify: true, 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'] }, options: { mangle: false } }, comments: { src: 'test/fixtures/src/comments.js', dest: 'tmp/comments.js', options: { mangle: false, preserveComments: 'some' } }, wrap: { src: 'test/fixtures/src/simple.js', dest: 'tmp/wrap.js', options: { mangle: false, wrap: 'testExport' } }, maxLineLen: { src: 'test/fixtures/src/simple2.js', dest: 'tmp/maxLineLen.js', options: { mangle: false, maxLineLen: 100 } }, ASCIIOnly: { src: 'test/fixtures/src/localization.js', dest: 'tmp/asciionly.js', options: { mangle: false, ASCIIOnly: 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 } }, sourcemap_basic: { src: 'test/fixtures/src/simple.js', dest: 'tmp/sourcemap_basic.js', options: { sourceMap: true } }, sourcemap_customName: { src: 'test/fixtures/src/simple.js', dest: 'tmp/sourcemap_customName.js', options: { sourceMap: true, sourceMapName: 'tmp/source_map_custom_name' } }, sourcemap_customDir: { src: 'test/fixtures/src/simple.js', dest: 'tmp/sourcemap_customDir.js', options: { sourceMap: true, sourceMapName: 'tmp/deep/directory/location/source_map.js.map' } }, sourcemap_customRoot: { 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_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', options: { sourceMap: true, sourceMapName: function(dest) { return dest + '.fn.map'; } } }, sourcemap_multiple: { files: { 'tmp/sourcemaps_multiple1.js': ['test/fixtures/src/simple.js'], 'tmp/sourcemaps_multiple2.js': ['test/fixtures/src/comments.js'] }, options: { sourceMap: true } }, sourcemap_multipleFunctionNames: { files: { 'tmp/sourcemaps_multiple1_fnName.js': ['test/fixtures/src/simple.js'], 'tmp/sourcemaps_multiple2_fnName.js': ['test/fixtures/src/comments.js'] }, options: { sourceMap: true, sourceMapName: function(dest) { return dest+'.fn.map'; } } }, sourcemapin: { files: { 'tmp/sourcemapin.js': ['test/fixtures/src/simple2.js'] }, options: { mangle: false, banner: '// Hello World\n', sourceMap: true, 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 } }, sourcemapin_sources: { files: { 'tmp/sourcemapin_sources.js': ['test/fixtures/src/simple2.js'] }, options: { sourceMap: 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, mangle: false, compress: false } }, expression_js: { files: { 'tmp/expression.js': ['test/fixtures/src/expression.js'] }, options: { expression: true, mangle: false, compress: false } }, mangleprops: { files: { 'tmp/mangleprops.js': ['test/fixtures/src/mangleprops.js'] }, options: { mangleProperties: true } }, mangleprops_withExcept: { files: { 'tmp/mangleprops_withExcept.js': ['test/fixtures/src/mangleprops.js'] }, options: { mangle: { except: ['dontMangleMeVariable'] }, mangleProperties: true } }, mangleprops_withExceptionsFiles: { files: { 'tmp/mangleprops_withExceptionsFiles.js': ['test/fixtures/src/mangleprops.js'] }, options: { mangle: { toplevel: true }, mangleProperties: true, exceptionsFiles: ['test/fixtures/src/exceptionsfile1.json', 'test/fixtures/src/exceptionsfile2.json'] } }, mangleprops_withExceptAndExceptionsFiles: { files: { 'tmp/mangleprops_withExceptAndExceptionsFiles.js': ['test/fixtures/src/mangleprops.js'] }, options: { mangle: { toplevel: true, except: ['dontMangleMeVariable'] }, mangleProperties: true, exceptionsFiles: ['test/fixtures/src/exceptionsfile1.json', 'test/fixtures/src/exceptionsfile2.json'] } }, mangleprops_withNameCacheFile: { files: { 'tmp/mangleprops_withNameCacheFile1.js': ['test/fixtures/src/mangleprops.js'], 'tmp/mangleprops_withNameCacheFile2.js': ['test/fixtures/src/mangleprops_withNameCache.js'] }, options: { mangle: { toplevel: true }, mangleProperties: true, nameCache: 'tmp/uglify_name_cache.json' } }, mangleprops_withRegex: { files: { 'tmp/mangleprops_withRegex.js': ['test/fixtures/src/mangleprops_withRegex.js'] }, options: { mangleProperties: { regex: /^[^#].*/ } } }, quotes_single: { files: { 'tmp/quotes_single.js': ['test/fixtures/src/quotes.js'] }, options: { quoteStyle: 1 } }, quotes_double: { files: { 'tmp/quotes_double.js': ['test/fixtures/src/quotes.js'] }, options: { quoteStyle: 2 } }, quotes_original: { files: { 'tmp/quotes_original.js': ['test/fixtures/src/quotes.js'] }, options: { quoteStyle: 3 } }, mangle_isNotObject: { files: { 'tmp/mangle.js': ['test/fixtures/src/simple.js'] }, mangle: true }, beautify_Object: { files: { 'tmp/beautify.js': ['test/fixtures/src/localization.js', 'test/fixtures/src/simple.js'] }, options: { beautify: { 'ascii_only': true, 'indent_start': 2, 'max_line_len': 40 } } } }, // Unit tests. nodeunit: { tests: ['test/*_test.js'] } }); // task that expects its argument (another task) to fail grunt.registerTask('expectFail', function() { var task = this.args.join(':'); var done = this.async(); function onComplete(error, result) { grunt.log.write('\n > ' + result.stdout.split('\n').join('\n > ') + '\n'); var rv = error ? true : new Error('Task ' + task + ' unexpectedly passed.'); done(rv); } grunt.util.spawn({ grunt: true, args: task }, onComplete); }); // Actually load this plugin's task(s). grunt.loadTasks('tasks'); // These plugins provide necessary tasks. grunt.loadNpmTasks('grunt-contrib-jshint'); grunt.loadNpmTasks('grunt-contrib-clean'); grunt.loadNpmTasks('grunt-contrib-nodeunit'); grunt.loadNpmTasks('grunt-contrib-internal'); // Whenever the "test" task is run, first clean the "tmp" dir, then run this // plugin's task(s), then test the result. grunt.registerTask('test', [ 'jshint', 'clean', 'uglify', 'nodeunit' ]); // By default, lint and run all tests. grunt.registerTask('default', ['test', 'build-contrib']); }; grunt-contrib-uglify-2.0.0/LICENSE-MIT000066400000000000000000000020641274343240600172460ustar00rootroot00000000000000Copyright (c) 2016 "Cowboy" Ben Alman, contributors 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. grunt-contrib-uglify-2.0.0/README.md000066400000000000000000000462051274343240600170760ustar00rootroot00000000000000# grunt-contrib-uglify v2.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 ## Getting Started If you haven't used [Grunt](http://gruntjs.com/) before, be sure to check out the [Getting Started](http://gruntjs.com/getting-started) guide, as it explains how to create a [Gruntfile](http://gruntjs.com/sample-gruntfile) as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command: ```shell npm install grunt-contrib-uglify --save-dev ``` Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript: ```js grunt.loadNpmTasks('grunt-contrib-uglify'); ``` ## Uglify task _Run this task with the `grunt uglify` command._ Task targets, files and options may be specified according to the grunt [Configuring tasks](http://gruntjs.com/configuring-tasks) guide. ### Migrating from 2.x to 3.x Version `3.x` introduced changes to configuring source maps. Accordingly, if you don't use the source map options you should be able to upgrade seamlessly. If you do use source maps, see below. #### Removed options `sourceMappingURL` - This is calculated automatically now `sourceMapPrefix` - No longer necessary for the above reason #### Changed options `sourceMap` - Only accepts a `Boolean` value. Generates a map with a default name for you `sourceMapRoot` - The location of your sources is now calculated for you when `sourceMap` is set to `true` but you can set manual source root if needed #### New options `sourceMapName` - Accepts a string or function to change the location or name of your map `sourceMapIncludeSources` - Embed the content of your source files directly into the map `expression` - Accepts a `Boolean` value. Parse a single expression (JSON or single functions) `quoteStyle` - Accepts integers `0` (default), `1`, `2`, `3`. Enforce or preserve quotation mark style. ### Options This task primarily delegates to [UglifyJS2][], so please consider the [UglifyJS documentation][] as required reading for advanced configuration. [UglifyJS2]: https://github.com/mishoo/UglifyJS2 [UglifyJS documentation]: http://lisperator.net/uglifyjs/ #### mangle Type: `Boolean` `Object` Default: `{}` 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). [View all options here](https://github.com/mishoo/UglifyJS2#mangler-options). #### compress Type: `Boolean` `Object` Default: `{}` Turn on or off source compression with default options. If an `Object` is specified, it is passed as options to `UglifyJS.Compressor()`. [View all options here](https://github.com/mishoo/UglifyJS2#compressor-options). #### beautify Type: `Boolean` `Object` Default: `false` Turns on beautification of the generated source code. An `Object` will be merged and passed with the options sent to `UglifyJS.OutputStream()`. [View all options here](https://github.com/mishoo/UglifyJS2#beautifier-options) ###### expression Type: `Boolean` Default: `false` Parse a single expression, rather than a program (for parsing JSON) #### report Choices: `'none'`, `'min'`, `'gzip'` Default: `'min'` Either report only minification result or report minification and gzip results. This is useful to see exactly how well UglifyJS is performing but using `'gzip'` will make the task take 5-10x longer to complete. [Example output](https://github.com/sindresorhus/maxmin#readme). If `'none'` is used the report will be generated on the verbose output. #### sourceMap Type: `Boolean` Default: `false` If `true`, a source map file will be generated in the same directory as the `dest` file. By default it will have the same basename as the `dest` file, but with a `.map` extension. #### sourceMapName Type: `String` `Function` Default: `undefined` To customize the name or location of the generated source map, pass a string to indicate where to write the source map to. If a function is provided, the uglify destination is passed as the argument and the return value will be used as the file name. #### sourceMapIn Type: `String` `Function` Default: `undefined` The location of an input source map from an earlier compilation, e.g. from CoffeeScript. If a function is provided, the uglify source is passed as the argument and the return value will be used as the sourceMap name. This only makes sense when there's one source file. #### sourceMapIncludeSources Type: `Boolean` Default: `false` Pass this flag if you want to include the content of source files in the source map as sourcesContent property. ###### sourceMapRoot Type: `String` Default: `undefined` With this option you can customize root URL that browser will use when looking for sources. 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` Wrap all of the code in a closure with a configurable arguments/parameters list. Each key-value pair in the `enclose` object is effectively an argument-parameter pair. #### 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. #### maxLineLen Type: `Number` Default: `32000` Limit the line length in symbols. Pass maxLineLen = 0 to disable this safety feature. #### ASCIIOnly Type: `Boolean` Default: `false` Enables to encode non-ASCII characters as \uXXXX. #### 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'` Turn on preservation of comments. - `false` will strip all comments - `'all'` will preserve all comments in code blocks that have not been squashed or dropped - `'some'` will preserve all comments that start with a bang (`!`) or include a closure compiler style 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` #### banner Type: `String` Default: `''` This string will be prepended to the minified output. Template strings (e.g. `<%= config.value %>` will be expanded automatically. #### footer Type: `String` Default: `''` This string will be appended to the minified output. Template strings (e.g. `<%= config.value %>` will be expanded automatically. #### screwIE8 Type: `Boolean` Default: `true` Set this to `false` if you still care about full compliance with Internet Explorer 6-8 quirks. #### mangleProperties Type: `Boolean` `Object` Default: `false` Turn on or off property mangling with default options. If an `Object` is specified, it is passed directly to `ast.mangle_properties()` (mimicking command line behavior). [View all options here](https://github.com/mishoo/UglifyJS2#mangler-options). #### reserveDOMProperties Type: `Boolean` Default: `false` Use this flag in conjunction with `mangleProperties` to prevent built-in browser object properties from being mangled. #### exceptionsFiles Type: `Array` Default: `[]` Use this with `mangleProperties` to pass one or more JSON files containing a list of variables and object properties that should not be mangled. See the [UglifyJS docs](https://www.npmjs.com/package/uglify-js) for more info on the file syntax. #### nameCache Type: `String` Default: `''` A string that is a path to a JSON cache file that uglify will create and use to coordinate symbol mangling between multiple runs of uglify. Note: this generated file uses the same JSON format as the `exceptionsFiles` files. #### quoteStyle Type: `Integer` Default: `0` Preserve or enforce quotation mark style. * `0` will use single or double quotes such as to minimize the number of bytes (prefers double quotes when both will do) * `1` will always use single quotes * `2` will always use double quotes * `3` will preserve original quotation marks ### Usage examples #### Basic compression This configuration will compress and mangle the input files using the default options. ```js // Project configuration. grunt.initConfig({ uglify: { my_target: { files: { 'dest/output.min.js': ['src/input1.js', 'src/input2.js'] } } } }); ``` #### No mangling Specify `mangle: false` to prevent changes to your variable and function names. ```js // Project configuration. grunt.initConfig({ uglify: { options: { mangle: false }, my_target: { files: { 'dest/output.min.js': ['src/input.js'] } } } }); ``` #### Reserved identifiers You can specify identifiers to leave untouched with an `except` array in the `mangle` options. ```js // Project configuration. grunt.initConfig({ uglify: { options: { mangle: { except: ['jQuery', 'Backbone'] } }, my_target: { files: { 'dest/output.min.js': ['src/input.js'] } } } }); ``` #### Source maps Generate a source map by setting the `sourceMap` option to `true`. The generated source map will be in the same directory as the destination file. Its name will be the basename of the destination file with a `.map` extension. Override these defaults with the `sourceMapName` attribute. ```js // Project configuration. grunt.initConfig({ uglify: { my_target: { options: { sourceMap: true, sourceMapName: 'path/to/sourcemap.map' }, files: { 'dest/output.min.js': ['src/input.js'] } } } }); ``` #### Advanced source maps Set the `sourceMapIncludeSources` 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 // Project configuration. grunt.initConfig({ uglify: { my_target: { options: { sourceMap: true, sourceMapIncludeSources: true, sourceMapIn: 'example/coffeescript-sourcemap.js', // input sourcemap from a previous compilation }, files: { 'dest/output.min.js': ['src/input.js'], }, }, }, }); ``` Refer to the [UglifyJS SourceMap Documentation](http://lisperator.net/uglifyjs/codegen#source-map) for more information. #### Turn off console warnings Specify `drop_console: true` as part of the `compress` options to discard calls to `console.*` functions. This will suppress warning messages in the console. ```js // Project configuration. grunt.initConfig({ uglify: { options: { compress: { drop_console: true } }, my_target: { files: { 'dest/output.min.js': ['src/input.js'] } } } }); ``` #### 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. _Note that manual configuration will require you to explicitly set `beautify: true` if you want traditional, beautified output._ ```js // Project configuration. grunt.initConfig({ uglify: { my_target: { options: { beautify: true }, files: { 'dest/output.min.js': ['src/input.js'] } }, my_advanced_target: { options: { beautify: { width: 80, beautify: true } }, files: { 'dest/output.min.js': ['src/input.js'] } } } }); ``` #### Banner comments In this example, running `grunt uglify:my_target` will prepend a banner created by interpolating the `banner` template string with the config object. Here, those properties are the values imported from the `package.json` file (which are available via the `pkg` config property) plus today's date. _Note: you don't have to use an external JSON file. It's also valid to create the `pkg` object inline in the config. That being said, if you already have a JSON file, you might as well reference it._ ```js // Project configuration. grunt.initConfig({ pkg: grunt.file.readJSON('package.json'), uglify: { options: { banner: '/*! <%= pkg.name %> - v<%= pkg.version %> - ' + '<%= grunt.template.today("yyyy-mm-dd") %> */' }, my_target: { files: { 'dest/output.min.js': ['src/input.js'] } } } }); ``` #### 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). See [UglifyJS global definitions documentation](http://lisperator.net/uglifyjs/compress#global-defs) for more information. ```js // Project configuration. grunt.initConfig({ uglify: { options: { compress: { global_defs: { 'DEBUG': false }, dead_code: true } }, my_target: { files: { 'dest/output.min.js': ['src/input.js'] } } } }); ``` #### Compiling all files in a folder dynamically This configuration will compress and mangle the files dynamically. ```js // Project configuration. grunt.initConfig({ uglify: { my_target: { files: [{ expand: true, cwd: 'src/js', src: '**/*.js', dest: 'dest/js' }] } } }); ``` #### Turn on object property name mangling This configuration will turn on object property name mangling, but not mangle built-in browser object properties. Additionally, variables and object properties listed in the `myExceptionsFile.json` will be mangled. For more info, on the format of the exception file format please see the [UglifyJS docs](https://www.npmjs.com/package/uglify-js). ```js // Project configuration. grunt.initConfig({ uglify: { options: { mangleProperties: true, reserveDOMCache: true, exceptionsFiles: [ 'myExceptionsFile.json' ] }, my_target: { files: { 'dest/output.min.js': ['src/input.js'] } } } }); ``` #### Turn on use of name mangling cache Turn on use of name mangling cache to coordinate mangled symbols between outputted uglify files. uglify will the generate a JSON cache file with the name provided in the options. Note: this generated file uses the same JSON format as the `exceptionsFiles` files. ```js // Project configuration. grunt.initConfig({ uglify: { options: { nameCache: '.tmp/grunt-uglify-cache.json', }, my_target: { files: { 'dest/output1.min.js': ['src/input1.js'], 'dest/output2.min.js': ['src/input2.js'] } } } }); ``` ## Release History * 2016-07-19   v2.0.0   Update uglify-js to v2.7.0. `screwIE8` is enabled by default. * 2016-07-19   v1.0.2   Update grunt to ^1.0.0. Fix `beautify` when passed as an object. Fix docs about `report` values. * 2016-03-16   v1.0.1   Downgrade maxmin for Node.js 0.10. * 2016-03-04   v1.0.0   Use uglify-js ~2.6.2 to fix sourcemap issue. Improve 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   Update lodash to ^4.0.1. Update grunt-contrib-clean to ^0.7.0. Update grunt-contrib-jshint to ^0.12.0. * 2015-11-20   v0.11.0   Update uglify-js to ~2.6.0. * 2015-11-12   v0.10.1   Update uglify-js to ~2.5. * 2015-10-27   v0.10.0   Update uglify-js to ^2.5. * 2015-08-24   v0.9.2   Update uglify-js to ^2.4.24 * 2015-04-07   v0.9.1   More fixes for `mangle` options. * 2015-04-07   v0.9.0   Add hook into uglify-js's mangling functionality. * 2015-03-30   v0.8.1   Lock uglify-js to 2.4.17 due to breaking changes. * 2015-02-19   v0.8.0   Add `screwIE8` option. Fix issue with explicit `compress` in Node.js 0.12.0. * 2014-12-23   v0.7.0   Add `sourceMapRoot` options. Update readme descriptions. Remove reference to clean-css. * 2014-09-17   v0.6.0   Output fixes. Add `ASCIIOnly` option. Other fixes. * 2014-07-25   v0.5.1   Update chalk to ^0.5.1. Output updates. * 2014-03-01   v0.4.0   Remove grunt-lib-contrib dependency and add more colors. * 2014-02-27   v0.3.3   Remove unnecessary calls to `grunt.template.process`. * 2014-01-22   v0.3.2   Fix handling of `sourceMapIncludeSources` option. * 2014-01-20   v0.3.1   Fix relative path issue in sourcemaps. * 2014-01-16   v0.3.0   Refactor sourcemap support. * 2013-11-09   v0.2.7   Prepend banner if `sourceMap` option not set, addresses #109. * 2013-11-08   v0.2.6   Merge #45, #53, #85 (#105 by way of duping #53). Add support for banners in uglified files with sourcemaps. Update docs. * 2013-10-28   v0.2.5   Add warning for banners when using sourcemaps. * 2013-09-02   v0.2.4   Update sourcemap format via #83. * 2013-06-10   v0.2.3   Add `footer` option. * 2013-05-31   v0.2.2   Revert #56 due to #58 until [chrome/239660](https://code.google.com/p/chromium/issues/detail?id=239660&q=sourcemappingurl&colspec=ID%20Pri%20M%20Iteration%20ReleaseBlock%20Cr%20Status%20Owner%20Summary%20OS%20Modified) [firefox/870361](https://bugzilla.mozilla.org/show_bug.cgi?id=870361) drop. * 2013-05-22   v0.2.1   Update uglify-js to ~2.3.5 #55 #40. Change `sourcemappingUrl` syntax #56. Disable sorting of names for consistent mangling #44. Update docs for `sourceMapRoot` #47 #25. * 2013-03-14   v0.2.0   No longer report gzip results by default. Support `report` option. * 2013-01-30   v0.1.2   Add better error reporting. Support for dynamic names of multiple sourcemaps. * 2013-02-15   v0.1.1   First official release for Grunt 0.4.0. * 2013-01-18   v0.1.1rc6   Update grunt/gruntplugin dependencies to rc6. Change in-development grunt/gruntplugin dependency versions from tilde version ranges to specific versions. * 2013-01-09   v0.1.1rc5   Update to work with grunt v0.4.0rc5. Switch back to `this.files` API. * 2012-11-28   v0.1.0   Work in progress, not officially released yet. --- Task submitted by ["Cowboy" Ben Alman](http://benalman.com) *This file was generated on Tue Jul 19 2016 16:46:21.* grunt-contrib-uglify-2.0.0/appveyor.yml000066400000000000000000000015411274343240600202010ustar00rootroot00000000000000clone_depth: 10 version: "{build}" # What combinations to test environment: matrix: - nodejs_version: "0.10" platform: x86 - nodejs_version: "0.12" platform: x86 - nodejs_version: "4" platform: x64 - nodejs_version: "4" platform: x86 - nodejs_version: "5" platform: x86 - nodejs_version: "6" platform: x86 install: - ps: Install-Product node $env:nodejs_version $env:platform - npm install test_script: # Output useful info for debugging - node --version && npm --version # We test multiple Windows shells because of prior stdout buffering issues # filed against Grunt. https://github.com/joyent/node/issues/3584 - ps: "npm test # PowerShell" # Pass comment to PS for easier debugging - cmd: npm test build: off matrix: fast_finish: true cache: - node_modules -> package.json grunt-contrib-uglify-2.0.0/docs/000077500000000000000000000000001274343240600165405ustar00rootroot00000000000000grunt-contrib-uglify-2.0.0/docs/uglify-examples.md000066400000000000000000000151721274343240600222030ustar00rootroot00000000000000# Usage examples ## Basic compression This configuration will compress and mangle the input files using the default options. ```js // Project configuration. grunt.initConfig({ uglify: { my_target: { files: { 'dest/output.min.js': ['src/input1.js', 'src/input2.js'] } } } }); ``` ## No mangling Specify `mangle: false` to prevent changes to your variable and function names. ```js // Project configuration. grunt.initConfig({ uglify: { options: { mangle: false }, my_target: { files: { 'dest/output.min.js': ['src/input.js'] } } } }); ``` ## Reserved identifiers You can specify identifiers to leave untouched with an `except` array in the `mangle` options. ```js // Project configuration. grunt.initConfig({ uglify: { options: { mangle: { except: ['jQuery', 'Backbone'] } }, my_target: { files: { 'dest/output.min.js': ['src/input.js'] } } } }); ``` ## Source maps Generate a source map by setting the `sourceMap` option to `true`. The generated source map will be in the same directory as the destination file. Its name will be the basename of the destination file with a `.map` extension. Override these defaults with the `sourceMapName` attribute. ```js // Project configuration. grunt.initConfig({ uglify: { my_target: { options: { sourceMap: true, sourceMapName: 'path/to/sourcemap.map' }, files: { 'dest/output.min.js': ['src/input.js'] } } } }); ``` ## Advanced source maps Set the `sourceMapIncludeSources` 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 // Project configuration. grunt.initConfig({ uglify: { my_target: { options: { sourceMap: true, sourceMapIncludeSources: true, sourceMapIn: 'example/coffeescript-sourcemap.js', // input sourcemap from a previous compilation }, files: { 'dest/output.min.js': ['src/input.js'], }, }, }, }); ``` Refer to the [UglifyJS SourceMap Documentation](http://lisperator.net/uglifyjs/codegen#source-map) for more information. ## Turn off console warnings Specify `drop_console: true` as part of the `compress` options to discard calls to `console.*` functions. This will suppress warning messages in the console. ```js // Project configuration. grunt.initConfig({ uglify: { options: { compress: { drop_console: true } }, my_target: { files: { 'dest/output.min.js': ['src/input.js'] } } } }); ``` ## 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. _Note that manual configuration will require you to explicitly set `beautify: true` if you want traditional, beautified output._ ```js // Project configuration. grunt.initConfig({ uglify: { my_target: { options: { beautify: true }, files: { 'dest/output.min.js': ['src/input.js'] } }, my_advanced_target: { options: { beautify: { width: 80, beautify: true } }, files: { 'dest/output.min.js': ['src/input.js'] } } } }); ``` ## Banner comments In this example, running `grunt uglify:my_target` will prepend a banner created by interpolating the `banner` template string with the config object. Here, those properties are the values imported from the `package.json` file (which are available via the `pkg` config property) plus today's date. _Note: you don't have to use an external JSON file. It's also valid to create the `pkg` object inline in the config. That being said, if you already have a JSON file, you might as well reference it._ ```js // Project configuration. grunt.initConfig({ pkg: grunt.file.readJSON('package.json'), uglify: { options: { banner: '/*! <%= pkg.name %> - v<%= pkg.version %> - ' + '<%= grunt.template.today("yyyy-mm-dd") %> */' }, my_target: { files: { 'dest/output.min.js': ['src/input.js'] } } } }); ``` ## 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). See [UglifyJS global definitions documentation](http://lisperator.net/uglifyjs/compress#global-defs) for more information. ```js // Project configuration. grunt.initConfig({ uglify: { options: { compress: { global_defs: { 'DEBUG': false }, dead_code: true } }, my_target: { files: { 'dest/output.min.js': ['src/input.js'] } } } }); ``` ## Compiling all files in a folder dynamically This configuration will compress and mangle the files dynamically. ```js // Project configuration. grunt.initConfig({ uglify: { my_target: { files: [{ expand: true, cwd: 'src/js', src: '**/*.js', dest: 'dest/js' }] } } }); ``` ## Turn on object property name mangling This configuration will turn on object property name mangling, but not mangle built-in browser object properties. Additionally, variables and object properties listed in the `myExceptionsFile.json` will be mangled. For more info, on the format of the exception file format please see the [UglifyJS docs](https://www.npmjs.com/package/uglify-js). ```js // Project configuration. grunt.initConfig({ uglify: { options: { mangleProperties: true, reserveDOMCache: true, exceptionsFiles: [ 'myExceptionsFile.json' ] }, my_target: { files: { 'dest/output.min.js': ['src/input.js'] } } } }); ``` ## Turn on use of name mangling cache Turn on use of name mangling cache to coordinate mangled symbols between outputted uglify files. uglify will the generate a JSON cache file with the name provided in the options. Note: this generated file uses the same JSON format as the `exceptionsFiles` files. ```js // Project configuration. grunt.initConfig({ uglify: { options: { nameCache: '.tmp/grunt-uglify-cache.json', }, my_target: { files: { 'dest/output1.min.js': ['src/input1.js'], 'dest/output2.min.js': ['src/input2.js'] } } } }); ``` grunt-contrib-uglify-2.0.0/docs/uglify-options.md000066400000000000000000000147631274343240600220650ustar00rootroot00000000000000# Options This task primarily delegates to [UglifyJS2][], so please consider the [UglifyJS documentation][] as required reading for advanced configuration. [UglifyJS2]: https://github.com/mishoo/UglifyJS2 [UglifyJS documentation]: http://lisperator.net/uglifyjs/ ## mangle Type: `Boolean` `Object` Default: `{}` 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). [View all options here](https://github.com/mishoo/UglifyJS2#mangler-options). ## compress Type: `Boolean` `Object` Default: `{}` Turn on or off source compression with default options. If an `Object` is specified, it is passed as options to `UglifyJS.Compressor()`. [View all options here](https://github.com/mishoo/UglifyJS2#compressor-options). ## beautify Type: `Boolean` `Object` Default: `false` Turns on beautification of the generated source code. An `Object` will be merged and passed with the options sent to `UglifyJS.OutputStream()`. [View all options here](https://github.com/mishoo/UglifyJS2#beautifier-options) #### expression Type: `Boolean` Default: `false` Parse a single expression, rather than a program (for parsing JSON) ## report Choices: `'none'`, `'min'`, `'gzip'` Default: `'min'` Either report only minification result or report minification and gzip results. This is useful to see exactly how well UglifyJS is performing but using `'gzip'` will make the task take 5-10x longer to complete. [Example output](https://github.com/sindresorhus/maxmin#readme). If `'none'` is used the report will be generated on the verbose output. ## sourceMap Type: `Boolean` Default: `false` If `true`, a source map file will be generated in the same directory as the `dest` file. By default it will have the same basename as the `dest` file, but with a `.map` extension. ## sourceMapName Type: `String` `Function` Default: `undefined` To customize the name or location of the generated source map, pass a string to indicate where to write the source map to. If a function is provided, the uglify destination is passed as the argument and the return value will be used as the file name. ## sourceMapIn Type: `String` `Function` Default: `undefined` The location of an input source map from an earlier compilation, e.g. from CoffeeScript. If a function is provided, the uglify source is passed as the argument and the return value will be used as the sourceMap name. This only makes sense when there's one source file. ## sourceMapIncludeSources Type: `Boolean` Default: `false` Pass this flag if you want to include the content of source files in the source map as sourcesContent property. #### sourceMapRoot Type: `String` Default: `undefined` With this option you can customize root URL that browser will use when looking for sources. 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` Wrap all of the code in a closure with a configurable arguments/parameters list. Each key-value pair in the `enclose` object is effectively an argument-parameter pair. ## 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. ## maxLineLen Type: `Number` Default: `32000` Limit the line length in symbols. Pass maxLineLen = 0 to disable this safety feature. ## ASCIIOnly Type: `Boolean` Default: `false` Enables to encode non-ASCII characters as \uXXXX. ## 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'` Turn on preservation of comments. - `false` will strip all comments - `'all'` will preserve all comments in code blocks that have not been squashed or dropped - `'some'` will preserve all comments that start with a bang (`!`) or include a closure compiler style 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` ## banner Type: `String` Default: `''` This string will be prepended to the minified output. Template strings (e.g. `<%= config.value %>` will be expanded automatically. ## footer Type: `String` Default: `''` This string will be appended to the minified output. Template strings (e.g. `<%= config.value %>` will be expanded automatically. ## screwIE8 Type: `Boolean` Default: `true` Set this to `false` if you still care about full compliance with Internet Explorer 6-8 quirks. ## mangleProperties Type: `Boolean` `Object` Default: `false` Turn on or off property mangling with default options. If an `Object` is specified, it is passed directly to `ast.mangle_properties()` (mimicking command line behavior). [View all options here](https://github.com/mishoo/UglifyJS2#mangler-options). ## reserveDOMProperties Type: `Boolean` Default: `false` Use this flag in conjunction with `mangleProperties` to prevent built-in browser object properties from being mangled. ## exceptionsFiles Type: `Array` Default: `[]` Use this with `mangleProperties` to pass one or more JSON files containing a list of variables and object properties that should not be mangled. See the [UglifyJS docs](https://www.npmjs.com/package/uglify-js) for more info on the file syntax. ## nameCache Type: `String` Default: `''` A string that is a path to a JSON cache file that uglify will create and use to coordinate symbol mangling between multiple runs of uglify. Note: this generated file uses the same JSON format as the `exceptionsFiles` files. ## quoteStyle Type: `Integer` Default: `0` Preserve or enforce quotation mark style. * `0` will use single or double quotes such as to minimize the number of bytes (prefers double quotes when both will do) * `1` will always use single quotes * `2` will always use double quotes * `3` will preserve original quotation marks grunt-contrib-uglify-2.0.0/docs/uglify-overview.md000066400000000000000000000022071274343240600222260ustar00rootroot00000000000000Task targets, files and options may be specified according to the grunt [Configuring tasks](http://gruntjs.com/configuring-tasks) guide. # Migrating from 2.x to 3.x Version `3.x` introduced changes to configuring source maps. Accordingly, if you don't use the source map options you should be able to upgrade seamlessly. If you do use source maps, see below. ## Removed options `sourceMappingURL` - This is calculated automatically now `sourceMapPrefix` - No longer necessary for the above reason ## Changed options `sourceMap` - Only accepts a `Boolean` value. Generates a map with a default name for you `sourceMapRoot` - The location of your sources is now calculated for you when `sourceMap` is set to `true` but you can set manual source root if needed ## New options `sourceMapName` - Accepts a string or function to change the location or name of your map `sourceMapIncludeSources` - Embed the content of your source files directly into the map `expression` - Accepts a `Boolean` value. Parse a single expression (JSON or single functions) `quoteStyle` - Accepts integers `0` (default), `1`, `2`, `3`. Enforce or preserve quotation mark style. grunt-contrib-uglify-2.0.0/package.json000066400000000000000000000015161274343240600201010ustar00rootroot00000000000000{ "name": "grunt-contrib-uglify", "description": "Minify JavaScript files with UglifyJS", "version": "2.0.0", "author": { "name": "Grunt Team", "url": "http://gruntjs.com/" }, "repository": "gruntjs/grunt-contrib-uglify", "license": "MIT", "engines": { "node": ">=0.10.0" }, "main": "tasks/uglify.js", "scripts": { "test": "grunt test" }, "dependencies": { "chalk": "^1.0.0", "lodash.assign": "^4.0.9", "maxmin": "^1.1.0", "uglify-js": "~2.7.0", "uri-path": "^1.0.0" }, "devDependencies": { "grunt": "^1.0.0", "grunt-contrib-clean": "^1.0.0", "grunt-contrib-internal": "^1.1.0", "grunt-contrib-jshint": "^1.0.0", "grunt-contrib-nodeunit": "^1.0.0" }, "keywords": [ "gruntplugin" ], "files": [ "tasks" ], "appveyor_id": "ybtf5vbvtenii561" } grunt-contrib-uglify-2.0.0/tasks/000077500000000000000000000000001274343240600167355ustar00rootroot00000000000000grunt-contrib-uglify-2.0.0/tasks/lib/000077500000000000000000000000001274343240600175035ustar00rootroot00000000000000grunt-contrib-uglify-2.0.0/tasks/lib/uglify.js000066400000000000000000000207641274343240600213510ustar00rootroot00000000000000/* * grunt-contrib-uglify * https://gruntjs.com/ * * Copyright (c) 2016 "Cowboy" Ben Alman, contributors * Licensed under the MIT license. */ 'use strict'; // External libs. var path = require('path'); var UglifyJS = require('uglify-js'); var assign = require('lodash.assign'); var uriPath = require('uri-path'); var getOutputOptions; exports.init = function(grunt) { var exports = {}; // Minify with UglifyJS. // From https://github.com/mishoo/UglifyJS2 // API docs at http://lisperator.net/uglifyjs/ exports.minify = function(files, dest, options) { options = options || {}; grunt.verbose.write('Minifying with UglifyJS...'); var topLevel = null; var totalCode = ''; var sourcesContent = {}; var outputOptions = getOutputOptions(options, dest); var output = UglifyJS.OutputStream(outputOptions); // Grab and parse all source files files.forEach(function(file) { var code = grunt.file.read(file); totalCode += code; // The src file name must be relative to the source map for things to work var basename = path.basename(file); var fileDir = path.dirname(file); 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); sourcesContent[file] = code; topLevel = UglifyJS.parse(code, { filename: file, toplevel: topLevel, expression: options.expression, bare_returns: bare_returns }); }); // Wrap code in a common js wrapper. if (options.wrap) { topLevel = topLevel.wrap_commonjs(options.wrap, options.exportAll); } // Wrap code in closure with configurable arguments/parameters list. if (options.enclose) { var argParamList = Object.keys(options.enclose).map(function(key) { return key + ':' + options.enclose[key]; }); topLevel = topLevel.wrap_enclose(argParamList); } var topLevelCache = null; if (options.nameCache) { topLevelCache = UglifyJS.readNameCache(options.nameCache, 'vars'); } // Need to call this before we mangle or compress, // and call after any compression or ast altering if (options.expression === false) { topLevel.figure_out_scope({ screw_ie8: options.screwIE8, cache: topLevelCache }); } if (options.compress !== false) { if (options.compress === true) { options.compress = {}; } if (options.compress.warnings !== true) { options.compress.warnings = false; } if (options.screwIE8 === false) { options.compress.screw_ie8 = false; } var compressor = UglifyJS.Compressor(options.compress); topLevel = topLevel.transform(compressor); // Need to figure out scope again after source being altered if (options.expression === false) { topLevel.figure_out_scope({ screw_ie8: options.screwIE8, cache: topLevelCache }); } } var mangleExclusions = { vars: [], props: [] }; if (options.reserveDOMProperties) { mangleExclusions = UglifyJS.readDefaultReservedFile(); } if (options.exceptionsFiles) { try { options.exceptionsFiles.forEach(function(filename) { mangleExclusions = UglifyJS.readReservedFile(filename, mangleExclusions); }); } catch (ex) { grunt.warn(ex); } } var cache = null; if (options.nameCache) { cache = UglifyJS.readNameCache(options.nameCache, 'props'); } if (typeof options.mangleProperties !== 'undefined' && options.mangleProperties !== false) { // if options.mangleProperties is a boolean (true) convert it into an object if (typeof options.mangleProperties !== 'object') { options.mangleProperties = {}; } options.mangleProperties.reserved = mangleExclusions ? mangleExclusions.props : null; options.mangleProperties.cache = cache; topLevel = UglifyJS.mangle_properties(topLevel, options.mangleProperties); if (options.nameCache) { UglifyJS.writeNameCache(options.nameCache, 'props', cache); } // Need to figure out scope again since topLevel has been altered if (options.expression === false) { topLevel.figure_out_scope({ screw_ie8: options.screwIE8, cache: topLevelCache }); } } if (options.mangle !== false) { if (options.mangle === true) { options.mangle = {}; } if (options.screwIE8 === false) { options.mangle.screw_ie8 = false; } // disabled due to: // 1) preserve stable name mangling // 2) it increases gzipped file size, see https://github.com/mishoo/UglifyJS2#mangler-options // // compute_char_frequency optimizes names for compression // topLevel.compute_char_frequency(options.mangle); // if options.mangle is a boolean (true) convert it into an object if (typeof options.mangle !== 'object') { options.mangle = {}; } options.mangle.cache = topLevelCache; options.mangle.except = options.mangle.except ? options.mangle.except : []; if (mangleExclusions.vars) { mangleExclusions.vars.forEach(function(name) { UglifyJS.push_uniq(options.mangle.except, name); }); } // Requires previous call to figure_out_scope // and should always be called after compressor transform topLevel.mangle_names(options.mangle); UglifyJS.writeNameCache(options.nameCache, 'vars', options.mangle.cache); } if (options.sourceMap && options.sourceMapIncludeSources) { for (var file in sourcesContent) { if (sourcesContent.hasOwnProperty(file)) { outputOptions.source_map.get().setSourceContent(file, sourcesContent[file]); } } } // Print the ast to OutputStream topLevel.print(output); var min = output.get(); // 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 var sourceMappingURL; sourceMappingURL = options.destToSourceMap.match(/^http[s]?:\/\//) === null ? uriPath(options.destToSourceMap) : options.destToSourceMap; min += '\n//# sourceMappingURL=' + sourceMappingURL; } var result = { max: totalCode, min: min, sourceMap: outputOptions.source_map }; grunt.verbose.ok(); return result; }; getOutputOptions = function(options, dest) { var outputOptions = { beautify: false, source_map: null }; if (options.banner && options.sourceMap) { outputOptions.preamble = options.banner; } if (options.screwIE8 === false) { outputOptions.screw_ie8 = false; } if (options.sourceMap) { var destBasename = path.basename(dest); var sourceMapIn; if (options.sourceMapIn) { sourceMapIn = grunt.file.readJSON(options.sourceMapIn); } outputOptions.source_map = UglifyJS.SourceMap({ file: destBasename, root: options.sourceMapRoot, orig: sourceMapIn }); if (options.sourceMapIncludeSources && sourceMapIn && sourceMapIn.sourcesContent) { sourceMapIn.sourcesContent.forEach(function(content, idx) { outputOptions.source_map.get().setSourceContent(sourceMapIn.sources[idx], content); }); } if (options.sourceMapIn) { outputOptions.source_map.get()._file = destBasename; } } if (typeof options.indentLevel !== 'undefined') { outputOptions.indent_level = options.indentLevel; } if (typeof options.maxLineLen !== 'undefined') { outputOptions.max_line_len = options.maxLineLen; } if (typeof options.ASCIIOnly !== 'undefined') { outputOptions.ascii_only = options.ASCIIOnly; } if (typeof options.quoteStyle !== 'undefined') { outputOptions.quote_style = options.quoteStyle; } if (typeof options.preserveComments !== 'undefined') { outputOptions.comments = options.preserveComments; } if (options.beautify) { if (typeof options.beautify === 'object') { assign(outputOptions, options.beautify); } else { outputOptions.beautify = true; } } return outputOptions; }; return exports; }; grunt-contrib-uglify-2.0.0/tasks/uglify.js000066400000000000000000000135171274343240600206010ustar00rootroot00000000000000/* * grunt-contrib-uglify * http://gruntjs.com/ * * Copyright (c) 2016 "Cowboy" Ben Alman, contributors * Licensed under the MIT license. */ 'use strict'; var path = require('path'); var chalk = require('chalk'); var maxmin = require('maxmin'); var err; // Return the relative path from file1 => file2 function relativePath(file1, file2) { var file1Dirname = path.dirname(file1); var file2Dirname = path.dirname(file2); if (file1Dirname !== file2Dirname) { return path.relative(file1Dirname, file2Dirname) + path.sep; } return ''; } // Converts \r\n to \n function normalizeLf(string) { return string.replace(/\r\n/g, '\n'); } module.exports = function(grunt) { // Internal lib. var uglify = require('./lib/uglify').init(grunt); grunt.registerMultiTask('uglify', 'Minify files with UglifyJS.', function() { // Merge task-specific and/or target-specific options with these defaults. var options = this.options({ banner: '', footer: '', compress: { warnings: false }, mangle: {}, beautify: false, report: 'min', expression: false, maxLineLen: 32000, ASCIIOnly: false, screwIE8: true, quoteStyle: 0 }); // Process banner. var banner = normalizeLf(options.banner); var footer = normalizeLf(options.footer); var mapNameGenerator, mapInNameGenerator; var createdFiles = 0; var createdMaps = 0; // 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 ' + chalk.cyan(filepath) + ' not found.'); return false; } return true; }); if (src.length === 0) { grunt.log.warn('Destination ' + chalk.cyan(f.dest) + ' not written because src files were empty.'); return; } // Warn on incompatible options if (options.expression && (options.compress || options.mangle)) { grunt.log.warn('Option ' + chalk.cyan('expression') + ' not compatible with ' + chalk.cyan('compress and mangle')); options.compress = false; options.mangle = false; } // function to get the name of the sourceMap if (typeof options.sourceMapName === 'function') { mapNameGenerator = options.sourceMapName; } // function to get the name of the sourceMapIn file if (typeof options.sourceMapIn === 'function') { if (src.length !== 1) { grunt.fail.warn('Cannot generate `sourceMapIn` for multiple source files.'); } mapInNameGenerator = options.sourceMapIn; } // dynamically create destination sourcemap name if (mapNameGenerator) { try { options.generatedSourceMapName = mapNameGenerator(f.dest); } catch (e) { err = new Error('SourceMap failed.'); err.origError = e; grunt.fail.warn(err); } // If no name is passed append .map to the filename } else if (!options.sourceMapName) { options.generatedSourceMapName = f.dest + '.map'; } else { options.generatedSourceMapName = options.sourceMapName; } // Dynamically create incoming sourcemap names if (mapInNameGenerator) { try { options.sourceMapIn = mapInNameGenerator(src[0]); } catch (e) { err = new Error('SourceMapInName failed.'); err.origError = e; grunt.fail.warn(err); } } // Calculate the path from the dest file to the sourcemap for the // sourceMappingURL reference // 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. var result; try { result = uglify.minify(src, f.dest, options); } catch (e) { console.log(e); err = new Error('Uglification failed.'); if (e.message) { err.message += '\n' + e.message + '. \n'; if (e.line) { err.message += 'Line ' + e.line + ' in ' + src + '\n'; } } err.origError = e; grunt.log.warn('Uglifying source ' + chalk.cyan(src) + ' failed.'); grunt.fail.warn(err); } // Concat minified source + footer var output = result.min + footer; // Only prepend banner if uglify hasn't taken care of it as part of the preamble if (!options.sourceMap) { output = banner + output; } // Write the destination file. grunt.file.write(f.dest, output); // Write source map if (options.sourceMap) { grunt.file.write(options.generatedSourceMapName, result.sourceMap); grunt.verbose.writeln('File ' + chalk.cyan(options.generatedSourceMapName) + ' created (source map).'); createdMaps++; } var outputSize = maxmin(result.max, output, options.report === 'gzip'); grunt.verbose.writeln('File ' + chalk.cyan(f.dest) + ' created: ' + outputSize); createdFiles++; }); if (createdMaps > 0) { grunt.log.ok(createdMaps + ' source' + grunt.util.pluralize(createdMaps, 'map/maps') + ' created.'); } if (createdFiles > 0) { grunt.log.ok(createdFiles + ' ' + grunt.util.pluralize(this.files.length, 'file/files') + ' created.'); } else { grunt.log.warn('No files created.'); } }); }; grunt-contrib-uglify-2.0.0/test/000077500000000000000000000000001274343240600165675ustar00rootroot00000000000000grunt-contrib-uglify-2.0.0/test/fixtures/000077500000000000000000000000001274343240600204405ustar00rootroot00000000000000grunt-contrib-uglify-2.0.0/test/fixtures/src/000077500000000000000000000000001274343240600212275ustar00rootroot00000000000000grunt-contrib-uglify-2.0.0/test/fixtures/src/comments.js000066400000000000000000000004241274343240600234120ustar00rootroot00000000000000/*! * I am a comment */ function foo() { return 42; } // @preserve preserve // @license license function bar() { return foo()*2; } /* @preserve * multiline preserve */ /* @license * multiline license */ function baz() { return bar()*bar(); } // end - not preservedgrunt-contrib-uglify-2.0.0/test/fixtures/src/exceptionsfile1.json000066400000000000000000000001151274343240600252210ustar00rootroot00000000000000{ "vars": ["dontMangleMeVariable2"], "props": ["dontMangleMeProperty"] } grunt-contrib-uglify-2.0.0/test/fixtures/src/exceptionsfile2.json000066400000000000000000000000701274343240600252220ustar00rootroot00000000000000{ "vars": ["dontMangleMeVariable3"], "props": [] } grunt-contrib-uglify-2.0.0/test/fixtures/src/expression.js000066400000000000000000000000511274343240600237600ustar00rootroot00000000000000function(doc) { emit(doc._id,doc); } grunt-contrib-uglify-2.0.0/test/fixtures/src/localization.js000066400000000000000000000005021274343240600242520ustar00rootroot00000000000000var set = [ "This is a random set of chαracters and strings.", "这是一组随机字符和字符串。", "Это случайный набор символов и строк", "Цé випадковий набір символів та рядків" ], answer = set[Math.floor(Math.random()*set.length)];grunt-contrib-uglify-2.0.0/test/fixtures/src/mangleprops.js000066400000000000000000000004001274343240600241060ustar00rootroot00000000000000var myObj = { myFunction: function(dontMangleMeVariable) { dontMangleMeVariable++; }, dontMangleMeProperty: function() {}, dontMangleMeProperty2: function() {} }; var dontMangleMeVariable2 = function() {}; var dontMangleMeVariable3 = function() {}; grunt-contrib-uglify-2.0.0/test/fixtures/src/mangleprops_withNameCache.js000066400000000000000000000000571274343240600266760ustar00rootroot00000000000000var myNumber = 10; myObj.myFunction(myNumber); grunt-contrib-uglify-2.0.0/test/fixtures/src/mangleprops_withRegex.js000066400000000000000000000000651274343240600261430ustar00rootroot00000000000000var anObject = { key1: 'val', '#key2': 'val2' }; grunt-contrib-uglify-2.0.0/test/fixtures/src/quotes.js000066400000000000000000000003731274343240600231100ustar00rootroot00000000000000function llama() { var a = 'This is a single quote string'; var b = "This is a double quote string"; var c = { "this": "is part of an Object", 'and': 'so is this', 'but': 'this one has "mixed" quotes: \'' }; return [a, b, c]; } grunt-contrib-uglify-2.0.0/test/fixtures/src/screwIE8.js000066400000000000000000000001251274343240600232140ustar00rootroot00000000000000 // screw-ie8 false will not remove quotes var reserved_words = { 'class': true }; grunt-contrib-uglify-2.0.0/test/fixtures/src/simple.js000066400000000000000000000003671274343240600230640ustar00rootroot00000000000000 // Hello world, I'm a comment! var longNameA = 1; var longNameB = 2; function longFunctionC(argumentC,argumentD) { return longNameA + longNameB + argumentC + argumentD; } var result = longFunctionC(3,4); /*! I might be preserved, yay! */ grunt-contrib-uglify-2.0.0/test/fixtures/src/simple.json000066400000000000000000000001601274343240600234100ustar00rootroot00000000000000{ "employees": [ { "firstName": "John", "lastName": "Doe" } ] } grunt-contrib-uglify-2.0.0/test/fixtures/src/simple2.coffee000066400000000000000000000006351274343240600237570ustar00rootroot00000000000000# Assignment: number = 42 opposite = true # Conditions: number = -42 if opposite # Functions: square = (x) -> x * x # Arrays: list = [1, 2, 3, 4, 5] # Objects: math = root: Math.sqrt square: square cube: (x) -> x * square x # Splats: race = (winner, runners...) -> print winner, runners # Existence: alert "I knew it!" if elvis? # Array comprehensions: cubes = (math.cube num for num in list)grunt-contrib-uglify-2.0.0/test/fixtures/src/simple2.js000066400000000000000000000015231274343240600231410ustar00rootroot00000000000000// Generated by CoffeeScript 2.0.0-dev void function () { var cubes, list, math, number, opposite, race, square; number = 42; opposite = true; if (opposite) number = -42; square = function (x) { return x * x; }; list = [ 1, 2, 3, 4, 5 ]; math = { root: Math.sqrt, square: square, cube: function (x) { return x * square(x); } }; race = function (winner, runners) { runners = 2 <= arguments.length ? [].slice.call(arguments, 1) : []; return print(winner, runners); }; if ('undefined' !== typeof elvis && null != elvis) alert('I knew it!'); cubes = function (accum$) { var num; for (var i$ = 0, length$ = list.length; i$ < length$; ++i$) { num = list[i$]; accum$.push(math.cube(num)); } return accum$; }.call(this, []); }.call(this); grunt-contrib-uglify-2.0.0/test/fixtures/src/simple2.map000066400000000000000000000023431274343240600233030ustar00rootroot00000000000000{"version":3,"file":"test/fixtures/src/simple2.coffee","sources":["../test/fixtures/src/simple2.coffee"],"names":[],"mappings":"AAAC;;;EACA,MAAA,GAAW;EACX,QAAA,GAAW;EAGX,IAAgB,QAAhB,CAAA;AAAA,IAAA,MAAA,GAAS,CAAC;EAGV,MAAA,GAAS,SAAA,CAAA,CAAA,CAAA;WAAO,CAAA,CAAA,CAAA,CAAI;;EAGpB,IAAA,GAAO,CAAA;AAAA,IAAC,CAAD;AAAA,IAAI,CAAJ;AAAA,IAAO,CAAP;AAAA,IAAU,CAAV;AAAA,IAAa,CAAb;AAAA,EAAA;EAGP,IAAA,GACG,CAAA;AAAA,IAAA,IAAA,EAAQ,IAAI,KAAZ;AAAA,IACD,MAAA,EAAQ,MADP;AAAA,IAED,IAAA,EAAQ,SAAA,CAAA,CAAA,CAAA;aAAO,CAAA,CAAA,CAAA,CAAI,MAAA,CAAO,CAAP;KAFlB;AAAA,EAAA;EAKD,IAAA,GAAO,SAAA,CAAA,MAAA,EAAA,OAAA,CAAA;IAAS;WACf,KAAA,CAAM,MAAN,EAAc,OAAd;;EAGD,2BAAsB,KAAA,CAAA,EAAA,SAAA,KAAtB,CAAA;AAAA,IAAA,KAAA,CAAM,YAAN;EAGF,KAAA;;IAAS,2BAAyB,YAAzB,aAAA,CAAA,KAAA,CAAA;MAAkB,MAAO;kBAAzB,IAAI,KAAJ,CAAU,GAAV","sourcesContent":["# Assignment:\nnumber = 42\nopposite = true\n\n# Conditions:\nnumber = -42 if opposite\n\n# Functions:\nsquare = (x) -> x * x\n\n# Arrays:\nlist = [1, 2, 3, 4, 5]\n\n# Objects:\nmath =\n root: Math.sqrt\n square: square\n cube: (x) -> x * square x\n\n# Splats:\nrace = (winner, runners...) ->\n print winner, runners\n\n# Existence:\nalert \"I knew it!\" if elvis?\n\n# Array comprehensions:\ncubes = (math.cube num for num in list)"]}grunt-contrib-uglify-2.0.0/test/uglify_test.js000066400000000000000000000043251274343240600214670ustar00rootroot00000000000000'use strict'; var grunt = require('grunt'); var path = require('path'); var read = function() { var filepath = path.join.apply(this, Array.prototype.slice.call(arguments)); return grunt.util.normalizelf(grunt.file.read(filepath)); }; exports.contrib_uglify = { preuglified_files: function(test) { var files = [ 'beautify.js', 'comments.js', 'compress.js', 'compress_explicit.js', 'compress_mangle.js', 'compress_mangle_banner.js', 'compress_mangle_beautify.js', 'compress_mangle_except.js', 'enclose.js', 'multifile.js', 'wrap.js', 'maxLineLen.js', 'asciionly.js', 'exportAll.js', 'screwIE8.js', 'sourcemap_basic.js', 'sourcemap_basic.js.map', 'sourcemap_customDir.js', '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'), 'sourcemapin.js', 'sourcemapin.js.map', 'sourcemap_sources.js.map', 'sourcemapin_sources.js', 'sourcemapin_sources.js.map', 'sourcemaps_multiple1.js', 'sourcemaps_multiple1.js.map', 'sourcemaps_multiple2.js', 'sourcemaps_multiple2.js.map', 'sourcemaps_multiple1_fnName.js', 'sourcemaps_multiple1_fnName.js.fn.map', 'sourcemaps_multiple2_fnName.js', 'sourcemaps_multiple2_fnName.js.fn.map', 'expression.json', 'expression.js', 'mangleprops.js', 'mangleprops_withExcept.js', 'mangleprops_withExceptionsFiles.js', 'mangleprops_withExceptAndExceptionsFiles.js', 'mangleprops_withNameCacheFile1.js', 'mangleprops_withNameCacheFile2.js', 'mangleprops_withRegex.js', 'uglify_name_cache.json', 'quotes_single.js', 'quotes_double.js', 'quotes_original.js' ]; test.expect(files.length); files.forEach(function(file) { var actual = read('tmp', file); var expected = read('test', 'fixtures', 'expected', file); test.equal(actual, expected, 'task output should equal ' + file); }); test.done(); } };