丑化失败.意外字符'`' [英] Uglification failed. Unexpected character '`'

查看:19
本文介绍了丑化失败.意外字符'`'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

gulp-uglify 无法丑化这段代码:

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>`

它抱怨字符:`.该字符适用于苹果的 JS 框架.我看不到 uglify 包中的任何内容来忽略这些字符和其中的文本字符串.我是否遗漏了文档中的某些内容?

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 还没有对 ECMAScript 2015(又名 ES6,又名 Harmony)的官方支持,但稍作修改即可使用开发中的存储库.

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.

操作方法:

  1. 打开控制台进入

cd node_modules/gulp-uglify

  1. 编辑 package.json

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

  1. 控制台输入:

npm 更新

它已准备好再次运行 .pipe(uglify())

替代解决方案

  1. 通过 npm 下载以下内容:
  1. Download the following via npm:

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

  1. gulpfile.js 中添加以下要求:
  1. Add the following requires in the gulpfile.js:

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

  1. gulp 任务如下:

gulp.task('uglify', function(){gulp.src('*.js').pipe(通天塔({预设:['es2015']})).pipe(uglify().on('error', function(e){控制台.log(e);})).pipe(gulp.dest('js'));});

它的作用是将所有 EcmaScript 2015 JS 代码转换为 EcmaScript5,然后对其进行 uglifying.

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

这篇关于丑化失败.意外字符'`'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆