我安装了yeoman并启动了官方文档中提供的示例。我浏览了的建议操作
yo webapp
bower install underscore
grunt
跑完呼噜声后,我收到了信息
grunt-cli: The grunt command line interface. (v0.1.9)
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已安装
npm install -g grunt-cli
和
npm install -g grunt
yo已经在项目根目录中生成了Gruntfile.js,我正在运行该命令
包.json也已生成:
"name": "testyo",
"version": "0.0.0",
"dependencies": {},
"devDependencies": {
"grunt": "~0.4.1",
"grunt-contrib-copy": "~0.4.1",
"grunt-contrib-concat": "~0.1.3",
"grunt-contrib-coffee": "~0.6.5",
"grunt-contrib-uglify": "~0.2.0",
"grunt-contrib-compass": "~0.2.0",
"grunt-contrib-jshint": "~0.4.1",
"grunt-contrib-cssmin": "~0.6.0",
"grunt-contrib-connect": "~0.2.0",
"grunt-contrib-clean": "~0.4.0",
"grunt-contrib-htmlmin": "~0.1.3",
"grunt-contrib-imagemin": "~0.1.3",
"grunt-contrib-watch": "~0.4.0",
"grunt-rev": "~0.1.0",
"grunt-autoprefixer": "~0.1.20130516",
"grunt-usemin": "~0.1.10",
"grunt-mocha": "~0.3.0",
"grunt-open": "~0.2.0",
"grunt-svgmin": "~0.1.0",
"grunt-concurrent": "~0.1.0",
"matchdep": "~0.1.1",
"connect-livereload": "~0.2.0"
},
"engines": {
"node": ">=0.8.0"
}
此外。从根目录
grunt --version
grunt-cli v0.1.9
这确认了grunt可以在每个目录中运行
知道吗?
经过一些快速研究,我从grunt文档中意识到,必须在项目中安装grunt。我通过运行做到了这一点
sudo npm install grunt --save-dev
现在grunt工作了。
我还需要运行:
npm install
从而加载所有的依赖关系。
这解决了我的问题。老实说,我以为yeoman会自动完成最后两步。
如果您有意见或认为有更好的解决方案,请留言。
npm cache clean
sudo npm install grunt --save-dev
真的帮了我一把
我遇到了同样的问题。
运行npm install
后,请确保在项目的根目录中创建了node_modules文件夹。这是放置"本地咕哝"的文件夹。如果文件夹不在那里,请检查您的npm配置npm config ls
,并确保您有global=false
。
我在这里找到了解决方案:https://stackoverflow.com/a/13449393/1046584