Kevin Lewis Kevin Lewis - 28 days ago 13
Javascript Question

Gruntfile.js - Task "default" not found

Here is my Gruntfile.js

module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON("package.json"),

uglify: {
options: {
mangle: true
}
build: {
src: "js/*.js",
dest: "js/min/script.js"
}
}

});

grunt.loadNpmTasks("grunt-contrib-uglify");

grunt.registerTask('default', [uglify]);

};





Here is my package.json - I have run
npm install
already, with all of the plugins that I will use in my Gruntfile, grunt-contrib-uglify is among them.

{
"name": "bootbuckle",
"version": "0.1.0",
"engines": {
"node": ">= 0.10.0"
},
"devDependencies": {
"grunt": "~0.4.2",
"grunt-contrib-watch": "~0.5.3",
"grunt-contrib-sass": "~0.6.0",
"grunt-csscomb": "~2.0.1",
"grunt-contrib-htmlmin": "~0.1.3",
"grunt-contrib-imagemin": "~0.4.1",
"grunt-contrib-uglify": "~0.2.7"
}
}





When I simply run
grunt
in the terminal - here is the error

build: {
^^^^^
Loading "Gruntfile.js" tasks...ERROR
>> SyntaxError: Unexpected identifier
Warning: Task "default" not found. Use --force to continue.
Aborted due to warnings.


Thanks in advance for any help you may be able to provide.




EDIT
Following Matti's guidance I have inserted a missing comma, a new error is now being thrown

Loading "Gruntfile.js" tasks...ERROR
>> ReferenceError: uglify is not defined
Warning: Task "default" not found. Use --force to continue.
Aborted due to warnings.

Answer

You missed a comma here:

    uglify: {
      options: {
        mangle: true
      }, // <-------
      build: {
        src: "js/*.js",
        dest: "js/min/script.js"
      }
    }

Edit: as posted by japrescott, you have to define uglify task as string.

grunt.registerTask('default', ["uglify"]);
Comments