简体   繁体   English

Grunt Uglify无法通过ES6

[英]Grunt Uglify Failing on ES6 For…of

I'm using grunt to uglify three JavaScript files: 我正在使用grunt来丑化三个JavaScript文件:

  1. functions.js functions.js
  2. formdata.min.js formdata.min.js
  3. page-contact.js 页面contact.js

I'm getting this error: 我收到此错误:

Warning: Uglification failed.
Name expected.
Line 38 in src/js/functions.js
 Use --force to continue.

Line 38 of functions.js : functions.js第38行:

for (var [id, value] of formData.entries()) {

Is this failing on the for...of or the formData? 这是在for ... of或formData上失败吗?

The Gruntfile.js : Gruntfile.js

module.exports = function(grunt) {
  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    watch: {
      uglify: {
        files: [ 'src/js/*' ],
        tasks: 'uglify'
      }
    },
    uglify: {
      my_target: {
        files: {
          'public/js/<%= pkg.name %>.min.js': ['src/js/*.js']
        }
      }
    }
  });

  grunt.loadNpmTasks('grunt-contrib-watch');
  grunt.loadNpmTasks('grunt-contrib-uglify');

};

Solved this by switching to the harmony branch of grunt-contrib-uglify . 通过切换到grunt-contrib-uglify和声分支来解决此问题。 The master branch doesn't support ES6 at this time. master分支目前不支持ES6。

In my packages.json I swapped out the original line for this and ran npm install : 在我的packages.json中,我换成原始行并运行npm install

"grunt-contrib-uglify": "git://github.com/gruntjs/grunt-contrib-uglify.git#harmony"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM