无法 run/find JSHint
Unable to run/find JSHint
G运行t 的全新尝试将配置文件放在一起并遇到一些困难。我正在尝试 运行 JSHint,但无法找到该文件。
目录设置为
./htdocs/[js, css, sass, images, html files]
./build/[]
.node_modules/[grunt,grunt-contrib-compass/watch/htmlmin/uglify, jshint, matchdep]
./Gruntfile.js, package.json
目前使用 npm install jshint -g
全局安装 JSHint
下一个运行宁jshint -v
returnsjshint v2.6.3
所以这告诉我它已经安装并且在我的 node_modules 目录中
我的 Gruntfile.js 读作
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 文件:
{
"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"
]
}
现在每次我 运行 grunt
我都得到 Error: Task "jshint" not found
我试过将 "jshint": "^2.6.3"
放在 "devDependencies" 数组中但是没有似乎也无济于事。有什么建议吗?
它说找不到 任务,而不是 jshint 可执行文件。
您需要像 documentation 中那样定义 Grunt 任务:
// Project configuration.
grunt.initConfig({
jshint: {
all: ['Gruntfile.js', 'lib/**/*.js', 'test/**/*.js']
}
});
编辑:当然,您的 package.json 中也需要 grunt-contrib-jshint
。
G运行t 的全新尝试将配置文件放在一起并遇到一些困难。我正在尝试 运行 JSHint,但无法找到该文件。
目录设置为
./htdocs/[js, css, sass, images, html files]
./build/[]
.node_modules/[grunt,grunt-contrib-compass/watch/htmlmin/uglify, jshint, matchdep]
./Gruntfile.js, package.json
目前使用 npm install jshint -g
全局安装 JSHint
下一个运行宁jshint -v
returnsjshint v2.6.3
所以这告诉我它已经安装并且在我的 node_modules 目录中
我的 Gruntfile.js 读作
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 文件:
{
"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"
]
}
现在每次我 运行 grunt
我都得到 Error: Task "jshint" not found
我试过将 "jshint": "^2.6.3"
放在 "devDependencies" 数组中但是没有似乎也无济于事。有什么建议吗?
它说找不到 任务,而不是 jshint 可执行文件。
您需要像 documentation 中那样定义 Grunt 任务:
// Project configuration.
grunt.initConfig({
jshint: {
all: ['Gruntfile.js', 'lib/**/*.js', 'test/**/*.js']
}
});
编辑:当然,您的 package.json 中也需要 grunt-contrib-jshint
。