导语
这个标题好像毫无吸引力,如何在github上发起一个开源项目,这个还需要一篇文章来写吗?创建一个项目,推送源码不就行了?想想是很有道理的,但是这样的项目,多半都会无人问津,自己也不点开,最终烂尾了。本文以一个前端项目为例,介绍一下如何在github上发起一个有质量的开源项目。当然,我们是抛开项目本身是否有吸引力、代码写得是否写得好,等主观影响大的因素的。
在 github 上新建一个空项目,然后 clone 到本地,进行开发。开发好了之后,将代码 push 到 github 上。
#clone代码到本地 [email protected]:username/repos.gi
t#进行开开发...
#提交代码 gitadd. gitcommit-m"initialcommit" #推送代码gitpush-uoriginmaster
因为是前端的项目,安装依赖通常有npm、bower两种,所以确定好项目名称之后,请到npm上占坑。
首先你需要在https://npmjs.com上注册一个帐号,填写用户名、邮箱、密码。
然后在本地的终端,通过npm adduser命令,添加你的帐号信息,需要输入刚才注册帐号时的用户名、邮箱和密码。
然后确保项目中的package.json文件,包含了必要的信息,例如项目名称、版本、主页、作者、协议、入口文件等。以WeUI项目为例:
{
"name": "weui",
"version": "0.4.0",
"description": "A UI library by WeChat official design team, includes the most useful widgets/modules in mobile web applications.",
"keywords": ["weui","wechat","weixin","css","less","mobile"],
"style": "dist/style/weui.css",
"less": "src/style/weui.less",
"main": "dist/style/weui.css",
"scripts": {
"start": "gulp -ws",
"test": "gulp release"
},
"author": "wechat ui team",
"repository": {
"type": "git",
"url": "https://github.com/weui/weui.git"
},
"homepage": "https://github.com/weui/weui",
"bugs": {
"url": "https://github.com/weui/weui/issues"
},
"license": "MIT",
"devDependencies": {}
}
然后使用npm publish命令,将项目发布到 npm 上,供其他人下载使用。
npmpublish.
发布成功之后,你就可以在https://www.npmjs.com/package/packagename是看到项目信息了。其他人可以通过npm install |