Validation failed. Unexpected character '' '

gulp -uglify cannot guess this piece of code:

var alertString = `<?xml version="1.0" encoding="UTF-8" ?> <document> <alertTemplate> <title>${title}</title> <description>${description}</description> </alertTemplate> </document>` 

he complains about the symbol: `. The symbol is valid for the Apple JS framework. I don't see anything inside the uglify package to ignore these characters and the text string inside it. Am I missing something from the documentation?

+5
source share
1 answer

Gulp -uglify does not yet have official support for ECMAScript 2015 (aka ES6, aka Harmony), but with a little modification you can use the on-development repository.

How to:

  • Open the 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 he is ready to run .pipe(uglify()) again


Alternative solution

  • Download the following via npm :

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

  1. Add the following to gulpfile.js :

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

  1. The gulp task will be as follows:

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 means is translating all of JS EcmaScript 2015 code into EcmaScript5, and then guessing it.

+13
source

Source: https://habr.com/ru/post/1238848/


All Articles