npm发布包流程详解 有demo

2019-12-06 11:01:31

参考链接 动手上传自己的npm包

npm发布包步骤,以及踩过的坑(见红颜色标准):


1.注册npm账号,并完成Email认证(否则最后一步提交会报Email错误)


2.npm添加用户或登陆:npm adduser 或 npm login


 


 3.更改npm源


平时我们可能用的是淘宝的镜像路径,而淘宝的镜像只有下载功能,不支持上次npm包。所以先把npm源改回来,等到发布成功后再改回来


4.制作自己的npm包


在目录下新建一个npm包的文件夹,如npmDemojsl,尽量取得特殊一点,不然很容易很已有的冲突

cmd进入目录下,运行npm init,生成package.json文件



编写主文件:index.js(npm init默认的入口文件是index.js,这可以自己定义)

随便写一个简单的hello输出: 


var hello = function(msg) {

    console.log('hello'+msg)

}

module.exports = hello 

 5.发布npm包:npm publish 




登陆我们的npm,也可以看到我们发布的包 




到这里,我们发布的第一个npm包就成功了!


6.使用和验证我们的包


npm install npmdemo2jsl 下载我们刚刚上次的包

引入该包,编写测试test.js

const a = require('npmdemo2jsl')

a('jsl')

 运行test.js:node test.js 


  • 2017-11-10 00:06:15

    CORS: credentials mode is 'include'

    XMLHttpRequest cannot load http://localhost/Foo.API/token. The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'. Origin 'http://localhost:5000' is therefore not allowed access. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute.

  • 2017-11-19 00:17:51

    Java如何获取Date的“昨天”与“明天”示例代码

    最近在做项目的时候用到Date和Calendar比较多,而且用到的方式也比较全,突然想到一个问题,Java如何获取Date的"昨天"与"明天",也就是前一天和后一天呢?思考后写出了方法,想着万一以后用到,就总结出来,也方便有需要的朋友们参考借鉴,下面来一起看看吧。

  • 2017-11-23 02:00:51

    js 分页插件twbs-pagination

    ​cdn地址 http://www.bootcdn.cn/twbs-pagination/ 官网地址 可以在cdn地址上面查看到