Back

安装grunt (Unable to find local grunt)

发布时间: 2015-02-24 02:10:00

refer to:  http://stackoverflow.com/questions/13925916/fatal-error-unable-to-find-local-grunt

grunt的安装有点儿奇怪. 

grunt的最新版本是 0.4, 而通过 npm install grunt 得到的版本是0.3 

所以,如果你发现这个错误: Unable to find local grunt , 那就继续往下看:  

所以,我们需要两步: 

1. 先安装 grunt-cli :

npm install -g grunt-cli

2. 修改你的 package.json:  记得要有下面两行: (如果没有package.json 的话,就直接 $ npm init 来新建)

{
  "devDependencies": {
    "grunt": "^0.4.5"
  }
}

然后执行 $ npm install  来安装 grunt: 

$ npm install  
$ grunt --version 
# => 
grunt-cli v0.1.13
grunt v0.4.5

3.  新建个 Gruntfile.coffee: 

module.exports = (grunt) ->
  grunt.loadNpmTasks 'grunt-contrib-coffee'
  grunt.registerTask 'default', [ 'coffee' ]

然后运行: 

$ grunt coffee
>> No "coffee" targets found.
Warning: Task "coffee" failed. Use --force to continue.

Aborted due to warnings.

虽然提示说coffee 没有运行成功, 但是这个是正常的提示了. 看到这里就说明 grunt在 "当前目录下" 是正常运行的

Back