最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to use uglify-es with gulp? - Stack Overflow

programmeradmin2浏览0评论

I'm using gulp to uglify my files and it works fine for older Javascript.

There has already been a question about how to uglify an ES6-javascript file: how to uglify javascript classes?

That's because my code does not work (classes are ES5 or smth):

gulp.task('handleJs', () => {
  gulp.src('src/frontend/xy/js/file.js')
    .pipe(uglify());
}

The answer doesn't seem to be up-to-date anymore because uglify-js-harmony is deprecated ().

It says, I should use uglify-es (not -js) but I don't find a solution, how to use it with gulp? Which npm-packages do I really need for that and how does the code have to look like?

I'm using gulp to uglify my files and it works fine for older Javascript.

There has already been a question about how to uglify an ES6-javascript file: how to uglify javascript classes?

That's because my code does not work (classes are ES5 or smth):

gulp.task('handleJs', () => {
  gulp.src('src/frontend/xy/js/file.js')
    .pipe(uglify());
}

The answer doesn't seem to be up-to-date anymore because uglify-js-harmony is deprecated (https://www.npmjs./package/uglify-js-harmony).

It says, I should use uglify-es (not -js) but I don't find a solution, how to use it with gulp? Which npm-packages do I really need for that and how does the code have to look like?

Share Improve this question asked Aug 6, 2017 at 14:42 hardforkhardfork 3,2914 gold badges29 silver badges53 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

This is documented to a degree in the README for gulp-uglify. For clarity, I've slightly modified the example there to match your snippet.

You need to npm install the pump, gulp-uglify, and uglify-es packages first (along with any other packages your project needs. Then, you can setup your gulp task similar to as follows:

var uglifyjs = require('uglify-es');
var poser = require('gulp-uglify/poser');
var pump = require('pump');

var minify = poser(uglifyjs, console);

gulp.task('handleJs', function (cb) {
  var options = {};

  pump([
      gulp.src('src/frontend/xy/js/file.js'),
      minify(options),
      gulp.dest('dist')
    ],
    cb
  );
});
发布评论

评论列表(0)

  1. 暂无评论