本文介绍了丑化失败。意想不到的字符'`'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! gulp-uglify无法隐藏这段代码: var alertString =`<?xml version = 1.0encoding =UTF-8?> <文件> < alertTemplate> < title> $ {title}< / title> < description> $ {description}< / description> < / alertTemplate> < / document>` 抱怨字符:`。该字符适用于苹果的JS框架。 我看不到uglify包内的任何内容忽略这些字符及其中的文本字符串。我是否缺少某些文档?解决方案 Gulp-uglify还没有官方支持ECMAScript 2015(又名ES6,又名Harmony ),但是可以使用开发中的存储库进行一些修改。 操作方法: 打开控制台并输入 cd node_modules / gulp-uglify 编辑package.json 依赖项: {uglify-js:git + https://github.com/mishoo/UglifyJS2.git#harmony}, 控制台输入: npm update 准备运行 .pipe(uglify ())再次 替代解决方案 通过 npm 下载以下内容: npm install --save-dev gulp-uglify gulp-babel babel-preset-es2015 在 gulpfile.js 中添加以下要求: var babel = require('gulp-babel'), uglify = requir E(吞掉-丑化); 吞食任务如下: gulp.task('uglify',function(){ gulp.src('*。js' ) .pipe(uglify()。on('error',function(e)) .pipe(babel({ presets:['es2015'] })) .pipe { console.log(e); })) .pipe(gulp.dest('js')); }); 这个功能是将所有的EcmaScript 2015 JS代码转储到EcmaScript5中,然后将其清除。 gulp-uglify is unable to uglify this piece of code: var alertString = `<?xml version="1.0" encoding="UTF-8" ?> <document> <alertTemplate> <title>${title}</title> <description>${description}</description> </alertTemplate> </document>`it complains at the character: `. The character is valid for the apple's JS framework.I can't see anything inside the uglify package to ignore those characters and the text string inside it. Am i missing something from the documentation? 解决方案 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:Open Console and entercd node_modules/gulp-uglifyEdit package.jsondependencies": { "uglify-js": "git+https://github.com/mishoo/UglifyJS2.git#harmony"},Console enter:npm updateAnd it is ready to run .pipe(uglify()) againAlternate SolutionDownload the following via npm:npm install --save-dev gulp-uglify gulp-babel babel-preset-es2015Add the following requires in the gulpfile.js:var babel = require('gulp-babel'), uglify = require('gulp-uglify');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. 这篇关于丑化失败。意想不到的字符'`'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-01 22:22