You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 3.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. # gulp-uglify [![][travis-shield-img]][travis-shield][![][appveyor-shield-img]][appveyor-shield][![][npm-dl-shield-img]][npm-shield][![][npm-v-shield-img]][npm-shield][![][coveralls-shield-img]][coveralls-shield]
  2. > Minify JavaScript with UglifyJS3.
  3. ## Installation
  4. Install package with NPM and add it to your development dependencies:
  5. `npm install --save-dev gulp-uglify`
  6. ## Usage
  7. ```javascript
  8. var gulp = require('gulp');
  9. var uglify = require('gulp-uglify');
  10. var pipeline = require('readable-stream').pipeline;
  11. gulp.task('compress', function () {
  12. return pipeline(
  13. gulp.src('lib/*.js'),
  14. uglify(),
  15. gulp.dest('dist')
  16. );
  17. });
  18. ```
  19. To help properly handle error conditions with Node streams, this project
  20. recommends the use of
  21. [`pipeline`](https://nodejs.org/docs/latest/api/stream.html#stream_stream_pipeline_streams_callback),
  22. from [`readable-stream`](https://github.com/nodejs/readable-stream).
  23. ## Options
  24. Most of the [minify options](https://github.com/mishoo/UglifyJS2#minify-options) from
  25. the UglifyJS API are supported. There are a few exceptions:
  26. 1. The `sourceMap` option must not be set, as it will be automatically configured
  27. based on your Gulp configuration. See the documentation for [Gulp sourcemaps][gulp-sm].
  28. [gulp-sm]: https://github.com/gulp-sourcemaps/gulp-sourcemaps#usage
  29. ## Errors
  30. `gulp-uglify` emits an 'error' event if it is unable to minify a specific file.
  31. The GulpUglifyError constructor is exported by this plugin for `instanceof` checks.
  32. It contains the following properties:
  33. - `fileName`: The full file path for the file being minified.
  34. - `cause`: The original UglifyJS error, if available.
  35. Most UglifyJS error messages have the following properties:
  36. - `message` (or `msg`)
  37. - `filename`
  38. - `line`
  39. To see useful error messages, see [Why Use Pipeline?](docs/why-use-pipeline/README.md#why-use-pipeline).
  40. ## Using a Different UglifyJS
  41. By default, `gulp-uglify` uses the version of UglifyJS installed as a dependency.
  42. It's possible to configure the use of a different version using the "composer" entry point.
  43. ```javascript
  44. var uglifyjs = require('uglify-js'); // can be a git checkout
  45. // or another module (such as `uglify-es` for ES6 support)
  46. var composer = require('gulp-uglify/composer');
  47. var pump = require('pump');
  48. var minify = composer(uglifyjs, console);
  49. gulp.task('compress', function (cb) {
  50. // the same options as described above
  51. var options = {};
  52. pump([
  53. gulp.src('lib/*.js'),
  54. minify(options),
  55. gulp.dest('dist')
  56. ],
  57. cb
  58. );
  59. });
  60. ```
  61. [travis-shield-img]: https://img.shields.io/travis/terinjokes/gulp-uglify/master.svg?label=Travis%20CI&style=flat-square
  62. [travis-shield]: https://travis-ci.org/terinjokes/gulp-uglify
  63. [appveyor-shield-img]: https://img.shields.io/appveyor/ci/terinjokes/gulp-uglify/master.svg?label=AppVeyor&style=flat-square
  64. [appveyor-shield]: https://ci.appveyor.com/project/terinjokes/gulp-uglify
  65. [npm-dl-shield-img]: https://img.shields.io/npm/dm/gulp-uglify.svg?style=flat-square
  66. [npm-shield]: https://yarnpkg.com/en/package/gulp-uglify
  67. [npm-v-shield-img]: https://img.shields.io/npm/v/gulp-uglify.svg?style=flat-square
  68. [coveralls-shield-img]: https://img.shields.io/coveralls/terinjokes/gulp-uglify/master.svg?style=flat-square
  69. [coveralls-shield]: https://coveralls.io/github/terinjokes/gulp-uglify