如何使用Grunt脚手架快速创建Node.js项目

2 篇文章 0 订阅
1 篇文章 0 订阅
  作者:zhanhailiang 日期:2014-11-17

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) http://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:
 
http://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.

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

6. 参考:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值