grunt-contrib-uglify v5.0.0 still unable to support ES6 Template Literals?

心不动则不痛 提交于 2021-01-29 06:07:05

问题


UPDATE, Jan 09, 2012:

At first, I thought it was due to the single quotes within the template literal:

replyTo: `'MTN Support' <${functions.config().supportgmail.email}>`

But now, it's confirmed that even a normal template literal is not supported by grunt-contrib-uglify:

throw new Error(`Unknown sender email address: ${mailOptions.from.address}.`);

Same Error:

Warning: Uglification failed.
Unexpected token: name «sender», expected: punc «,». 
Line 90 in functions/app-functions.js,functions/index.js,functions/viewer-functions.js,functions/site-functions.js
 Use --force to continue.

Note that even the uglify-js alone could not parse this. I'm also aware of the harmony or uglify-js-es6 version on GitHub, but as this is for production deployment purpose, I dare not use it because it has not been updated since 4 years ago.

So is it confirmed that grunt-contrib-uglify v5.0.0 is still not supporting ES6 Template Literals? Any other workarounds or alternative without changing the template literals to the traditional + string concatenation? Thanks!


Original Question:

I have the following Gruntfile.js:

module.exports = function (grunt) {
    grunt.initConfig({
        // define source files and their destinations
        uglify: {
            files: {
                src: 'functions/*.js',                  // source files mask
                dest: '../project-staging/functions/'  // destination folder
            }
        }
    });

    // load plugins
    grunt.loadNpmTasks('grunt-contrib-uglify');

    // register at least this one task
    grunt.registerTask('default', ['uglify']);

};

When I run grunt at the command line, I hit this error:

Warning: Uglification failed.
Unexpected token: string «MTN Support», expected: punc «,».
Line 44 in functions/app-functions.js,functions/index.js,functions/viewer-functions.js,functions/site-functions.js
 Use --force to continue.

Aborted due to warnings.

Below is the code that causes the error:

var mailOptions = {
    from: functions.config().supportgmail.email,
    to: null,
    cc: null,
    bcc: null,
    // This is the line that causes the error:
    replyTo: `'MTN Support' <${functions.config().supportgmail.email}>`,
    subject: null,
    text: null,
    html: null
};

I have no idea what the error means as I don't have any error running my code except when I try to uglify it with Grunt. I also heard that the latest version of grunt-contrib-uglify already support ES6, so what else could it be? Below is the version of my Grunt and plugin, which I just installed today:

  "devDependencies": {
    "grunt": "^1.3.0",
    "grunt-contrib-uglify": "^5.0.0"
  }

Anyone knows what's wrong with my code? I don't think it make sense to change my code to the old way of string concatenation using the + as the template string is everywhere in my entire project. Thanks in advance!

来源:https://stackoverflow.com/questions/65625390/grunt-contrib-uglify-v5-0-0-still-unable-to-support-es6-template-literals

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