Grunt Uglify在ES6上失败了

时间:2017-11-18 02:16:25

标签: javascript npm ecmascript-6 gruntjs grunt-contrib-uglify

我使用grunt来丑化三个JavaScript文件:

  1. functions.js
  2. formdata.min.js
  3. 页-contact.js
  4. 我收到此错误:

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

    functions.js的第38行:

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

    对于for ...或formData,这是否失败?

    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');
    
    };
    

1 个答案:

答案 0 :(得分:2)

通过切换到grunt-contrib-uglify的{​​{3}}来解决此问题。主分支目前不支持ES6。

在我的packages.json中,我换掉了原来的行并运行了npm install

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