Node.js教程 如何使用Grunt脚手架快速创建Node.js项目
沉沙 2018-10-25 来源 : 阅读 1058 评论 0

摘要:本篇教程介绍了Node.js教程 如何使用Grunt脚手架快速创建Node.js项目,希望阅读本篇文章以后大家有所收获,帮助大家对Node.js的理解更加深入。

本篇教程介绍了Node.js教程 如何使用Grunt脚手架快速创建Node.js项目,希望阅读本篇文章以后大家有所收获,帮助大家对Node.js的理解更加深入。

<


1. 安装node.js,npm工具(略)。

2. 安装grunt, grunt-init
npm install -g grunt-cli
npm install -g grunt-init

3. 下载脚手架:grunt-init-node - Create a Node.js
 module, including Nodeunit unit tests.
git clone git@github.com:billfeller/grunt-init-node.git ~/.grunt-init/node

注意,其默认路径为~/.grunt-init/xxxx,如果下载到默认路径,后续只需要通过grunt-init xxxx就可直接初始化;若下载到私人指定路径时,则grunt-init /path/to/template使用绝对路径来初始化。

4. 初始化:
[root@~/wade/nodejs/grunt-init-node-demo]# grunt-init node
Running "init:node" (init) task
This task will create one or more files in the current directory, based on the
environment and the answers to a few questions. Note that answering "?" to any
question will show question-specific help and answering "none" to most questions
will leave its value blank.
 
"node" template notes:
Project name shouldn‘t contain "node" or "js" and should be a unique ID not
already in use at search.npmjs.org.
 
Please answer the following:
[?] Project name (grunt-init-node-demo) 
[?] Description (The best project ever.) 
[?] Version (0.1.0) 
[?] Project git repository (git://github.com/billfeller/grunt-init-node-demo.git) 
[?] Project homepage (https://github.com/billfeller/grunt-init-node-demo) 
[?] Project issues tracker (https://github.com/billfeller/grunt-init-node-demo/issues) 
[?] Licenses (MIT) 
[?] Author name (billfeller) 
[?] Author email (billfeller@gmail.com) 
[?] Author url (none) //blog.csdn.net/billfeller
[?] What versions of node does it run on? (>= 0.8.0) 
[?] Main module/entry point (lib/grunt-init-node-demo) 
[?] Npm test command (grunt nodeunit) 
[?] Will this project be tested with Travis CI? (Y/n) Y
[?] Do you need to make any changes to the above before continuing? (y/N) N
 
Writing .gitignore...OK
Writing .jshintrc...OK
Writing .travis.yml...OK
Writing Gruntfile.js...OK
Writing README.md...OK
Writing lib/grunt-init-node-demo.js...OK
Writing test/grunt-init-node-demo_test.js...OK
Writing LICENSE-MIT...OK
Writing package.json...OK
 
Initialized from template "node".
You should now install project dependencies with npm install. After that, you
may execute project tasks with grunt. For more information about installing
and configuring Grunt, please see the Getting Started guide:
 
//gruntjs.com/getting-started
 
Done, without errors.

当看到“Done, without errors.”,就表示初始化成功,之后就可以开始专注于业务开发了。

注:如果在初始化时遇到如下提示:
[root@~/wade/nodejs]# grunt-init node
Running "init:node" (init) task
This task will create one or more files in the current directory, based on the
environment and the answers to a few questions. Note that answering "?" to any
question will show question-specific help and answering "none" to most questions
will leave its value blank.

Warning: Existing files may be overwritten! Use --force to continue.

Aborted due to warnings.

那是因为当前目录已经存在同名的相关文件,此时可以通过清除相关文件或者重建一个空目录来初始化。

5. grunt官方维护几个模板:


grunt-init-commonjs - Create a commonjs module, including Nodeunit unit tests.

grunt-init-gruntfile - Create a basic Gruntfile.

grunt-init-gruntplugin - Create a Grunt plugin, including Nodeunit unit tests.

grunt-init-jquery - Create a jQuery plugin, including QUnit unit tests.

grunt-init-node - Create a Node.js module, including Nodeunit unit tests.


可以参考以上做法初始化相关的项目。

   

本文由职坐标整理并发布,希望对同学们有所帮助。了解更多详情请关注WEB前端Node.js频道!

本文由 @沉沙 发布于职坐标。未经许可,禁止转载。
喜欢 | 0 不喜欢 | 0
看完这篇文章有何感觉?已经有0人表态,0%的人喜欢 快给朋友分享吧~
评论(0)
后参与评论

您输入的评论内容中包含违禁敏感词

我知道了

助您圆梦职场 匹配合适岗位
验证码手机号,获得海同独家IT培训资料
选择就业方向:
人工智能物联网
大数据开发/分析
人工智能Python
Java全栈开发
WEB前端+H5

请输入正确的手机号码

请输入正确的验证码

获取验证码

您今天的短信下发次数太多了,明天再试试吧!

提交

我们会在第一时间安排职业规划师联系您!

您也可以联系我们的职业规划师咨询:

小职老师的微信号:z_zhizuobiao
小职老师的微信号:z_zhizuobiao

版权所有 职坐标-一站式IT培训就业服务领导者 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
 沪公网安备 31011502005948号    

©2015 www.zhizuobiao.com All Rights Reserved

208小时内训课程