对于Grunt来说,这是一个全新的尝试,它试图将配置文件组合在一起,但遇到了一些困难。我正在尝试运行JSHint,无法找到该文件。
目录设置为
./htdocs/[js, css, sass, images, html files]
./build/[]
.node_modules/[grunt,grunt-contrib-compass/watch/htmlmin/uglify, jshint, matchdep]
./Gruntfile.js, package.json目前,JSHint是全局安装的,使用npm install jshint -g下一步运行jshint -v返回jshint 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“数组中,但这似乎也没有帮助。有什么建议吗?
发布于 2015-03-11 00:21:41
它是说找不到任务,而不是jshint可执行文件。
您需要像在文档中那样定义Grunt任务
// Project configuration.
grunt.initConfig({
jshint: {
all: ['Gruntfile.js', 'lib/**/*.js', 'test/**/*.js']
}
});编辑:当然,您也需要在您的package.json中包含package.json。
https://stackoverflow.com/questions/28976413
复制相似问题