加载“Gruntfile.js”任务SyntaxError

时间:2016-03-03 17:27:41

标签: javascript gruntjs

尝试运行grunt时出现以下错误;

Loading "Gruntfile.js" tasks...ERROR
SyntaxError: missing ) after argument list
Warning: Task "default" not found. Use --force to continue.
Aborted due to warnings.

我想知道是否有人可以帮我纠正这个问题?

这是我的Gruntfile:

module.exports = function(grunt) {

  // Project configuration.
  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    uglify: {
      options: {
        banner: '/*! <%= pkg.name %> <%= grunt.template.today("dd-mm-yyyy") %> */\n'
      },
      dist: {
        files: {
          'public/dist/js/<%= pkg.name %>.min.js' : ['public/src/js/<%= pkg.name %>.js']
        }
      },
      dev: {
        options: {
          compress: false,
          beautify: true,
          mangle: false
        },
        files: {
          'public/dist/js/<%= pkg.name %>.min.js' : ['public/src/js/<%= pkg.name %>.js']
        }
      }
    },
    imageoptim: {
      myTask: {
        src: ['public/src/img','public/dist/img']
      }
    },
    sass: {
      options: {
        banner: '/*! <%= pkg.name %> <%= grunt.template.today("dd-mm-yyyy") %> */\n'
      },
      dist: {
        options: {
          style: 'compressed'
        },
        files: {
          'public/dist/css/<%= pkg.name %>.min.css' : 'public/src/css/<%= pkg.name %>.scss'
        }
      },
      dev: {
        options: {
          style: 'expanded'
        },
        files: {
          'public/dist/css/<%= pkg.name %>.min.css' : 'public/src/css/<%= pkg.name %>.scss'
        }
      }
    },
    watch: {
      css: {
        files: ['public/src/css/*.scss'],
        tasks: ['sass:dev']
      },
      js: {
        files: ['public/src/js/*.js'],
        tasks: ['uglify:dev']
      }
    },
    concat: {
      options: {
        separator: ';'
      },
      dist: {
        src: ['public/src/js/jquery-1.10.2.js', 'public/src/js/plugins/*.js', 'public/src/js/main.js'],
        dest: 'public/dist/js/<%= pkg.name %>.js'
      }
    },
    eslint: {
      target: ['public/src/js/*.js']
    },
    webstandards: {
      dist: {
        src: ['public/dist']
      }
    },
    mochaTest: {
        test: {
            options: {
                reporter: 'spec',
                captureFile: 'results.txt'
            },
            src: ['public/src/js/**/*.js']
        }
    },
    clean: ['public/dist/css', 'public/dist/js']
  });

  // Load the plugin that provides the "uglify" task.
  grunt.loadNpmTasks('grunt-contrib-uglify');
  grunt.loadNpmTasks('grunt-contrib-sass');
  grunt.loadNpmTasks('grunt-contrib-watch');
  grunt.loadNpmTasks('grunt-contrib-clean');
  grunt.loadNpmTasks('grunt-contrib-concat');
  grunt.loadNpmTasks('grunt-eslint');
  grunt.loadNpmTasks('grunt-imageoptim');
  grunt.loadNpmTasks('grunt-webstandards');
  grunt.loadNpmTasks('grunt-mocha');
  grunt.loadNpmTasks('grunt-mocha-test');

  // Default task(s).
  grunt.registerTask('default', 'Dev Default Task', function() {
    grunt.log.writeln('\n********* RUNNING DEV TASKS -- NOT FOR PRODUCTION *********');
    grunt.task.run(['uglify:dev', 'sass:dev', 'eslint', 'mochaTest']);
  };
  // Optimize images.
  grunt.registerTask('img', ['imageoptim']);
  grunt.registerTask('dist', ['uglify:dist', 'sass:dist', 'webstandards:dist']);
  grunt.registerTask('dev', ['uglify:dev', 'sass:dev', 'eslint', 'mochaTest']);

};

1 个答案:

答案 0 :(得分:1)

第107行中的

(我认为)你错过了在第104行打开的结束)

这部分应解决问题......

// Default task(s).
grunt.registerTask('default', 'Dev Default Task', function() {
    grunt.log.writeln('\n********* RUNNING DEV TASKS -- NOT FOR PRODUCTION *********');
    grunt.task.run(['uglify:dev', 'sass:dev', 'eslint', 'mochaTest']);
});