Reputation: 1840
Brand new to Grunt trying to put together a configuration file and having some difficulties. I'm trying to run JSHint, and the file is unable to be found.
Directory set up is
./htdocs/[js, css, sass, images, html files]
./build/[]
.node_modules/[grunt,grunt-contrib-compass/watch/htmlmin/uglify, jshint, matchdep]
./Gruntfile.js, package.json
Currently JSHint is installed globally using npm install jshint -g
Next running jshint -v
returns jshint v2.6.3
So that's telling me it's installed plus it's in my node_modules directory
My Gruntfile.js reads as
module.exports = function(grunt) {
var globalConfig = {
src: 'htdocs',
dest: 'build'
};
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
globalConfig: globalConfig,
// CONFIG ===================================/
watch: {
css: {
files: ['**/*.scss'],
tasks: ['compass']
},
scripts: {
files: ['**/*.js'],
tasks: ['jshint'],
options: {
spawn: false
}
}
},
compass: {
options: {
sassDir: '<%= globalConfig.src %>/sass',
cssDir: '<%= globalConfig.dest %>/css'
},
dev: {}
}
});
// DEPENDENT PLUGINS =========================/
require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);
// TASKS =====================================/
grunt.registerTask('default', ['watch','jshint']);
}
package.json file:
{
"name": "Demo",
"version": "1.0.0",
"description": "Optimized template test",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "user",
"license": "ISC",
"devDependencies": {
"grunt": "^0.4.5",
"grunt-contrib-compass": "^1.0.1",
"grunt-contrib-htmlmin": "^0.4.0",
"grunt-contrib-uglify": "^0.8.0",
"grunt-contrib-watch": "^0.6.1",
"matchdep": "^0.3.0"
},
"dependencies": {
"grunt": "^0.4.5"
},
"keywords": [
"DemoOne"
]
}
Now every time I run grunt
I'm getting Error: Task "jshint" not found
I've tried putting "jshint": "^2.6.3"
inside the "devDependencies" array but that didn't seem to help either. Any suggestions?
Upvotes: 0
Views: 182
Reputation: 58898
It is saying a task cannot be found, not the jshint executable.
You need to define the Grunt task like in the documentation:
// Project configuration.
grunt.initConfig({
jshint: {
all: ['Gruntfile.js', 'lib/**/*.js', 'test/**/*.js']
}
});
EDIT: And of course you need to have grunt-contrib-jshint
in your package.json as well.
Upvotes: 1