Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unexpected identifier error in grunt.js file

Tags:

gruntjs

Can anyone tell me why I am getting the following error in terminal when running the following grunt.js file?

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

};

The error I get is:

Loading "gruntfile.js" tasks...ERROR

SyntaxError: Unexpected identifier Warning: Task "default" not found. Use --force to continue.

THANKS!

like image 371
Pete Norris Avatar asked Feb 05 '14 23:02

Pete Norris


1 Answers

You have a missing comma:

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

Make yourself a favor and use 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"
  ]
like image 144
Ilan Frumer Avatar answered Sep 23 '22 21:09

Ilan Frumer