丑化失败。意想不到的字符'`' [英] Uglification failed. Unexpected character '`'

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

问题描述

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 ),但是可以使用开发中的存储库进行一些修改。



操作方法:


  1. 打开控制台并输入

cd node_modules / gulp-uglify



< ol start =2>
  • 编辑package.json

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


    1. 控制台输入:

    npm update



    准备运行 .pipe(uglify ())再次






    替代解决方案


    1. 通过 npm 下载以下内容:

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


    1. gulpfile.js 中添加以下要求:

    var babel = require('gulp-babel'),
    uglify = requir E(吞掉-丑化);


    1. 吞食任务如下:

    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:

    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.

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

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