grunt.js文件中的意外标识符错误

时间:2014-02-05 23:16:05

标签: gruntjs

任何人都可以告诉我为什么在运行以下grunt.js文件时我在终端中收到以下错误?

module.exports = function(grunt) {

grunt.initConfig({

    pkg: grunt.file.readJSON('package.json'),

    concat: { // Here is where we do our concatenating
      dist: {
      src: [
      'components/js/*.js' // everything in the src js folder
    ],
    dest: 'js/script.js',
    }
    }

    uglify: {
    build: {
    src: 'js/script.js',
    dest: 'js/script.min.js'
    }
    }

});

//Add all the plugins here
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-uglify');

//What happens when we type 'grunt' in the terminal
grunt.registerTask('default', ['concat', 'uglify']);

};

我得到的错误是:

Loading "gruntfile.js" tasks...ERROR
  
    

SyntaxError:意外的标识符     警告:找不到任务“默认”。使用--force继续。

  

谢谢!

1 个答案:

答案 0 :(得分:12)

您的逗号缺失:

grunt.initConfig({

  pkg: grunt.file.readJSON('package.json'),

  concat: {
    dist: {
      src: [
        'components/js/*.js'
      ],
      dest: 'js/script.js',
    }
  }, // <---- here was a missing comma

  uglify: {
    build: {
      src: 'js/script.js',
      dest: 'js/script.min.js'
    }
  }
});

帮自己一个忙,并使用coffeescript!

module.exports = (grunt) ->
  grunt.initConfig

    pkg: grunt.file.readJSON("package.json")

    concat:
      dist:
        src: ["components/js/*.js"]
        dest: "js/script.js"

    uglify:
      build:
        src: "js/script.js"
        dest: "js/script.min.js"


  grunt.loadNpmTasks "grunt-contrib-concat"
  grunt.loadNpmTasks "grunt-contrib-uglify"

  grunt.registerTask "default", [
    "concat"
    "uglify"
  ]