我已经使用 sudo npm install -g grunt...
命令全局安装了 grunt
和 grunt-cli
。
我的工作文件夹是`/opt/web',请不要问为什么:)
检查 `/opt/web' 中的 grunt 版本:
$ grunt --version
grunt-cli v0.1.13
但是,我实际上无法从那里运行 grunt 任务:
$ grunt
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.
如果我在本地安装 grunt,它会要求在本地安装它的所有依赖项(已经在全局安装(!))。
我觉得这种行为很奇怪。
我的问题是:
这是错误还是功能?这是设计使然 grunt 只想使用本地安装的东西吗?
最佳答案
这是设计使然。查看grunt-cli readme .
除了查找并运行 grunt 的本地副本外,cli 不执行任何操作。
这意味着每个项目都可以使用项目指定的 grunt 版本,并且知道/测试可以正常工作。鉴于 grunt 可以做的关键事情的数量,这种兼容性 promise 很重要。
还有一个good blog post在 Node 站点上更多地讨论模块安装位置。
关于javascript - 为什么在全局安装时 grunt 不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24263445/