为什么grunt允许全局安装?

时间:2016-01-10 18:41:44

标签: gruntjs

我使用-g选项全局安装了grunt-cli和grunt。

然而,当我尝试运行grunt时,我收到此错误:

grunt --gruntfile /Users/a/root/config/Gruntfile.js
grunt-cli: The grunt command line interface. (v0.1.13)

Fatal error: Unable to find local grunt.

If you're seeing this message, either a Gruntfile wasn't found or grunt
hasn't been installed locally to your project. For more information about
installing and configuring grunt, please see the Getting Started guide:

http://gruntjs.com/getting-started

这很令人困惑,因为它似乎表示您要进行本地安装。

实际上似乎是矛盾的。我显然有一个grunt文件。

1 个答案:

答案 0 :(得分:0)

全局安装Grunt-cli,以便可以从系统上的任何位置运行grunt命令。如果没有全局安装,您需要依赖一些运行本地grunt安装(npm run-script和朋友)的抽象方法,这些方法对于此用途来说很笨拙。

entire point of the global install is only to load and run a local Gruntfile.js using the locally installed version of Grunt。错误消息表明:

  

找不到Gruntfile或者grunt尚未在本地安装到您的项目中。

换句话说,要运行Grunt,you need to create a Gruntfile.js,您必须在项目旁边安装Grunt的本地副本。 CLI就是在没有麻烦的小提琴的情况下开始这个过程的。