当前位置:网站首页>怎么发布一个自己的npm包
怎么发布一个自己的npm包
2022-07-19 18:59:00 【影风莫】
前期准备
- node环境,请去官网下载
- npm账号,请到此链接https://www.npmjs.com/signup 注册
创建项目
执行npm init -y
初始化项目
package.json文件:
{
"name": "demo",
"version": "1.0.0",
"description": "",
"main": "index.js",
"bin": {
"demo": "index.js"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}
index.js文件:
注意一定加上这行代码: #!/usr/bin/env node
表示在node环境下运行代码
#!/usr/bin/env node
console.log('测试!!!');
本地测试:
第一步: 当前发布包目录下发布到全局的node_modulesnpm link
去测试下直接输入自己package.json里的bin配置的命令,我这里配置的demo
结果为:
第二步: 本地测试项目目录下关联全局的发布发布包npm link publishname
取消关联:
本地测试完这部是有必要的.主要取消关联关系可以减少对开发造成依赖未装滞后等问题.
- 取消测试项目与全局的关联
在测试项目执行npm unlink publishname
- 取消发布项目与全局的关联
在发布包项目执行npm unlink publishname
发布线上:
大概有两步:
第一步: 登入账号.
执行 npm login
,没有npm本地账号的话需要执行 npm adduser 添加本地npm账号
如果这里登入报错,执行下 npm config set registry https://registry.npmjs.org
,一定要是npmjs源
第二步:发布到npmjs官网
执行 npm publish
注意: 如果这里报403的错误,没有权限提交到这个包仓库,原因是该包名已经被占用了,那修改下定义包的名字,需要在package.json文件修改name字段修改其名字,其名字必须在包名前面加上作用域名@username/packagename
这种格式命名,且username只能为当前用户, 执行 npm whoami 可以查看当前用户名
边栏推荐
- Androd发布JitPack开源项目(gradle7.2)
- Open a window and pop up a tool with favorite links
- 36 亿元、对象存储市场:XSKY 7亿、华为 6.9亿、杉岩 4.6亿、新华三 3.6亿、浪潮 3.2亿、中移 3亿
- 「运维有小邓」搜索日志数据以作为网络安全情报
- Custom attribute operation of DOM series
- The last technical problem baffles me: how to avoid the risk of production environment performance testing?
- STM32开发笔记118:在STM32CubeIDE中使用CMSIS DSP库
- ICML2022教程 | 因果公平性分析,68页pdf
- 4、图网络分类
- 银行业数据安全建设专题分析
猜你喜欢
【无标题】
1、图机器学习基础入门
DOM系列之自定义属性操作
当我们谈论不可变基础设施时,我们在谈论什么
Distribution and application of Internet of things technology in the industrial pattern of Internet of things
TZC 1283: simple sort - insert sort
Two methods of selecting objects in CAD frame, AutoCAD -- deleting duplicate line segments
LLVM pass pwn 入门 (3)
编译UE5.0
OpenCV 学习资料分享:中文、图文、代码注释并茂,建议收藏
随机推荐
基础测试干了4年,自学了自动化(太片面),突然接到被裁员消息
Web3.0 application architecture design evolution
编译UE5.0
永磁同步电机36问(一)——隐极电机与凸极电机有什么区别?
iNFTnews | 拥有99年历史的《TIME》正引领传统媒体进军NFT
为什么官方不建议使用uuid做MySQL主键
GEE(7):GEE插件Open Earth Engine extension提高效率
微信小程序的转发分享功能
Pure domestic! Ziguang SSD starts batch shipment!
Is it good or not to open an account at CITIC Securities? Is it safe? How to open an account
A game research and development company in Shenzhen installed monitoring for each station. Netizen: it's comparable to imprisonment!
3、Graph Neural Network
Soft test director: "after five years of work, you don't even know about the server interface test“
2022-7-18总结
又一 AI 公司(思必驰)申请上市:三年亏损 8.3 亿、营收 6.6 亿,研发投入 6.9 亿
38行PHP代码免导入数据库分析Linux访问日志
Special description of random() random function of C (an amazing feature of random function)
纯国产!紫光SSD开始批量出货!
服务器自动抢占GPU运行程序
[Network Communication II] TCP reference model