0

This is my first test in grunt:). Anyway,I want to test my javasrcipt code using the different grunt modules. They are all installed and you can see them,in a json file called package.json.

{
   "name": "LarissaCity",
   "private": true,
   "devDependencies": {
     "grunt": "^1.0.1",
     "grunt-contrib-jshint": "^1.1.0",
     "jit-grunt": "^0.10.0",
     "jshint-stylish": "^2.2.1",
     "time-grunt": "^1.4.0"
  },
  "engines": {
  "node": ">=0.10.0"
  }
}

Next I have a file called Gruntfile.js. And inside it use the installed modules to test my javascript code. So.

'use strict';

 // Time how long tasks take. Can help when optimizing build times
 require('time-grunt')(grunt);

 // Automatically load required Grunt tasks
 require('jit-grunt')(grunt);

 // Define the configuration for all the tasks
 grunt.initConfig({
 pkg: grunt.file.readJSON('package.json'),

 // Make sure code styles are up to par and there are no obvious mistakes
jshint: {
options: {
  jshintrc: '.jshintrc',
  reporter: require('jshint-stylish')
},

all: {
  src: [
    'Gruntfile.js',
    'app/scripts/{,*/}*.js'
  ]
  }
 }
});

grunt.registerTask('build', [
'jshint'
]);

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

When I type grunt in the cmd this comes up.

 Loading "Gruntfile.js" tasks...ERROR
 ReferenceError: grunt is not defined

So maybe there is something wrong in the Gruntfile.js. Any ideas?

Thanks,

Theo.

4
  • 2
    did you require('grunt')? Commented Feb 20, 2017 at 16:24
  • oops. I didn't. I will try again in a minute. Commented Feb 20, 2017 at 16:28
  • yes it's working! Commented Feb 20, 2017 at 16:38
  • 3
    Possible duplicate of Grunt is not defined Commented Feb 20, 2017 at 16:55

1 Answer 1

1

You will have to write your code in below block in gruntfile.js

    module.exports = function(grunt){
      //Your code here
    }
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.