【问题标题】:How to add grunt to my project?如何将 grunt 添加到我的项目中?
【发布时间】:2016-03-04 13:07:21
【问题描述】:
我是 grunt 的新手,我无法理解初始设置。我所做的只是安装了节点和咕噜声,这与我的项目无关。我的问题是
1. 如何将 grunt 添加到我的项目中。我正在使用角度项目。我必须在我的项目文件夹中添加 grunt 吗?如果是,我应该在哪里添加以及如何添加?
2. 很多文档说要更新 gruntfile.js。当我搜索时
可以在 grunt\node_modules 文件夹中看到这么多 gruntfile.js。哪个
我应该修改 gruntfile.js 文件吗?
【问题讨论】:
标签:
angularjs
node.js
gruntjs
【解决方案1】:
Grunt 实际上并没有进入您的 Angular 项目。只有应该在客户端浏览器中显示的库(即实际运行 web 应用程序)才应该注入到 Angular 中。
将 grunt 视为一种工具,可帮助您在 Angular 项目之外管理构建系统。
您可以运行npm install grunt --save-dev,它会创建一个package.json 文件,其中包含有关您的依赖项的信息。
www.egghead.io 有一些很好的学习 Grunt 和 Angular 的资源,http://build-podcast.com/ 也是如此。
考虑同时研究npm、gulp、webpack 和其他替代方案。
【解决方案2】:
- Step1 - 安装节点和 npm
- 第二步 - npm install -g grunt-cli
- Step3 - 在您的项目根文件夹中创建 Gruntfile.js。 Click here 示例文件
- Step4 - 注册一个任务
- Step5 - 运行 Grunt