我试图使用 grunt 并结合 gradle 来配置 jshint,而我正在尝试运行下面的任务是我面临的错误
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”任务...错误
以下是我遵循的步骤
包.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
}
}