发布npm包并关联github地址

一、先列一下总体的步骤:

图片.png

二、具体操作:
1:新建目录
<pre>
$ mkdir npm_module_test
</pre>
2:初始化,输入npm init,直接按enter下一步,在git repository步骤可先输入url占位
<pre>
$ cd npm_module_test/
$ npm init
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sensible defaults.

See npm help json for definitive documentation on these fields
and exactly what they do.

Use npm install <pkg> --save afterwards to install a package and
save it as a dependency in the package.json file.

Press ^C at any time to quit.
name: (npm_module_test)
version: (1.0.0)
description:
entry point: (index.js)
test command:
git repository: www.xxx.com
keywords:
author:
license: (ISC)
About to write to /Users/baidu/Desktop/work/npm/npm_module_test/package.json:

{
"name": "npm_module_test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo "Error: no test specified" && exit 1"
},
"repository": {
"type": "git",
"url": "www.xxx.com"
},
"author": "",
"license": "ISC"
}

Is this ok? (yes)

</pre>
3、创建index.js,输入下列代码
<pre>
function test(e) {
console.log(e);
};
exports.test = test;
</pre>
4、创建test.js,输入下列代码
<pre>
var Mynpm = require('./index.js');
Mynpm.test('hello');
</pre>
5、执行node test,确认输出正常
<pre>
$ node test.js
hello
</pre>
6、发布到github上,得到代码仓库地址
7、修改package.json中的git repository地址
8、发布到npm
a:https://www.npmjs.com注册账号
b:执行npm adduser
<pre>
$ npm adduser
Username: 注册的用户名
Password: 注册的密码
Email: (this IS public) 注册的邮箱
Logged in as 用户名 on http://registry.npmjs.org/.
</pre>
c:执行npm publish,如下则表示发布成功
<pre>
$ npm publish

  • 包名@1.0.0
    </pre>
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 175,790评论 25 709
  • 1. Java基础部分 基础部分的顺序:基本语法,类相关的语法,内部类的语法,继承相关的语法,异常的语法,线程的语...
    子非鱼_t_阅读 32,025评论 18 399
  • 学会了手机摄影的技巧,手机一样可以拍出不输数码相机的照片! 了解手机相机的特点 手机照相机不完全等同于大家理解...
    灯鱼啊阅读 8,815评论 0 9
  • 2008年的中秋节,难忘的一个台风天,那年大风大雨,那夜里儿子到来了。这家伙很会挑时间,是个小吃货。所以我们...
    新雨育儿知道阅读 1,631评论 0 2
  • 第三次meetup属于再次破冰吧! 先是每个人说本周月了什么。再是每个人对方的缺点。 nico主要看了一本书茶花女...
    文文的花期阅读 1,787评论 0 1