Uglification failed. Unexpected character '`'

狂风中的少年 提交于 2019-12-03 14:19:24

Gulp-uglify has yet no official support for ECMAScript 2015 (aka ES6, aka Harmony) but with a little modification the on-development repository can be used.

How-to:

  1. Open Console and enter

cd node_modules/gulp-uglify

  1. Edit package.json

dependencies": { "uglify-js": "git+https://github.com/mishoo/UglifyJS2.git#harmony" },

  1. Console enter:

npm update

And it is ready to run .pipe(uglify()) again


Alternate Solution

  1. Download the following via npm:

npm install --save-dev gulp-uglify gulp-babel babel-preset-es2015

  1. Add the following requires in the gulpfile.js:

var babel = require('gulp-babel'), uglify = require('gulp-uglify');

  1. The gulp task will be as follow:

gulp.task('uglify', function(){ gulp.src('*.js') .pipe(babel({ presets: ['es2015'] })) .pipe(uglify().on('error', function(e){ console.log(e); })) .pipe(gulp.dest('js')); });

What this does is transpile all the EcmaScript 2015 JS code to EcmaScript5 and then uglifies it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!