我试图使用grunt配合jshint并与gradle结合使用,而我尝试在下面运行我的任务是我面临的错误
Loading "jshint.js" tasks...ERROR
>> Error: Cannot find module 'jshint'
>> at Function.Module._resolveFilename (module.js:338:15)
>> at Function.Module._load (module.js:280:25)
>> at Module.require (module.js:364:17)
>> at require (module.js:380:17)
No tasks specified, running default tasks.
Running tasks: default
我正面临错误 - > 加载“jshint.js”任务...错误
以下是我遵循的步骤
的package.json
{
"name": "sample",
"version": "0.0.0",
"description": "sample project",
"main": "scripts/main.js",
"scripts": {
"test": "scripts/spec"
},
"repository": "",
"author": "",
"license": "BSD",
"devDependencies": {
"grunt": "~0.4.1",
"grunt-contrib-jshint": "~0.6.0"
}
}
Gruntfile.js
module.exports = function(grunt) {
grunt.initConfig({
jshint: {
files: ['gruntfile.js', 'vM/**/*.js'],
options: {
globals: {
jQuery: true,
console: true,
module: true
}
}
}
});
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.registerTask('test', 'jshint');
};
grunt.gradle
import org.apache.tools.ant.taskdefs.condition.Os
import org.gradle.api.tasks.Exec
def windows_source_dir = "C:\node_modules"
task jshint(type: GruntTask) {
dependsOn = ['gruntLink']
gruntArgs = "jshint"
workingDir 'src/main/webapp/'
}
task gruntLink(type: Exec) {
description = "Installs all Node.js dependencies defined in package.json"
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
commandLine 'cmd', 'mklink /D windows_source_dir src/main/webapp/node_modules'
} else {
commandLine = ["ln", "-nfs", "/usr/local/lib/node_modules/grunt_modules", "src/main/webapp/node_modules"]
}
}
class GruntTask extends Exec {
private String gruntExecutable = Os.isFamily(Os.FAMILY_WINDOWS) ? "grunt.cmd" : "grunt"
String gruntArgs = ""
public GruntTask() {
super()
this.setExecutable(gruntExecutable)
}
public void setGruntArgs(String gruntArgs) {
this.args = "$gruntArgs".trim().split(" ") as List
}
}
答案 0 :(得分:0)
您是否在项目目录的根目录中运行npm install
?您需要本地安装JSHint才能运行Grunt任务。 : - )
答案 1 :(得分:0)
最后在深入研究我的问题后,我自己找到了解决方案
我犯的错误是 - >我错误地拼写了Gruntfile.js,第一个字母是大写字母,但我把它像下面那样小了
files: ['gruntfile.js', 'vM/**/*.js'],