2015-10-15 121 views
0

我得到node.js安裝在Windows與npm包。
我有一個項目在D驅動器爲D:> projectD
我想與SASS,concat等一起運行jshint。所有工作正常,但得到錯誤的jshint爲:npm jshint安裝和工作Grunt&nodejs

Local npm module "jshint" not found.Is it installed? 
Warning: Task 'jshint' not found. Use --force to continue. 

有關安裝jshint的使用下面的命令:

npm install -g jshint 
D:>projectD>npm install --save-dev jshint 

Gruntfile.js

jshint:{ 
all: ['<%= meta.srcPath %>engine/js/myjs1.js'] 
}, 

//plugin declaration 
grunt.loadNpmTasks('jshint'); 

// Default task 
grunt.registerTask('default', ['concat','sass','jshint']); 

的package.json

{ 
    "name": "Test-Project", 
    "version": "0.1.0", 
    "devDependencies": { 
    "grunt": "~0.4.1", 
    "grunt-contrib-concat": "~0.1.3", 
    "grunt-sass": "^1.0.0", 
    "jshint": "^2.8.0" 
    } 
} 

C一個人幫我解決了爲什麼我不能使用jshint和grunt中的其他任務一起工作?

回答

1

其實你的Gruntfile是錯誤的。 你想配置Grunt。因此,你需要在你的情況

grunt.initConfig({ 
    jshint: { 
    all: ['<%= meta.srcPath %>engine/js/myjs1.js'] 
    } 
}); 

使用grunt.initConfig

所以要初始化配置並相信該模塊是grunt-contrib-jshint模塊,你需要的。 因此,您的loadNpmTask將爲grunt.loadNpmTasks('grunt-contrib-jshint'); 而您的registerTask只需包含jshint,因爲您只需加載並配置jshint

您缺少module.exports = function(grunt) { }。您需要將您的配置導出爲功能。

總而言之你的配置應該像下面

module.exports = function(grunt) { 

    grunt.initConfig({ 
    jshint: { 
     all: ['<%= meta.srcPath %>engine/js/myjs1.js'] 
     } 
    } 
    }); 

    grunt.loadNpmTasks('grunt-contrib-jshint'); 

    grunt.registerTask('default', ['jshint']); 

}; 
+0

Cank你好心解釋更具有行代碼左右?它不清...... – Deadpool

+0

當然是的。我只在我的手機上。 – Cludch