发布自己的npm工具包

发布自己的npm工具包

1.注册NPM 账号

注册地址:www.npmjs.com/

2.新建目录初始化项目

npm init

模块名称需遵循相关政策要求:https://www.npmjs.com/policies,模块名称不能和已有npm模块名称冲突
name 模块名 唯一性
version 版本
main 当你用require(‘modulename’)引用这个模块的时,引用的是哪个文件
keywords为别人搜索到你的包的关键字
author 作者

3.新建index.js

写自己的方法

exports.formatLinuxTime = function(data) {
    
    
    // 时间戳转换
    function timestampToTime(timestamp) {
    
    
        var date = new Date(timestamp); //时间戳为10位需*1000,时间戳为13位的话不需乘1000
        Y = date.getFullYear() + '-';
        M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
        D = date.getDate() < 10 ? '0' + (date.getDate()) + ' ' : date.getDate() + ' ';
        h = date.getHours() < 10 ? '0' + date.getHours() + ':' : date.getHours() + ':';
        m = date.getMinutes() < 10 ? '0' + date.getMinutes() + ':' : date.getMinutes() + ':';
        s = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds();
        return Y + M + D + h + m + s;
    }
    if (data) {
    
    
        let time = timestampToTime(data);
        return time
    }
    return '';
};
// console.log(formatLinuxTime(1615876200000))

4.登录npm 发布npm包

npm login
npm publish

5.安装包

npm install yyplugs

6.更新包

npm version patch
npm publish

7.撤销包

npm unpublish --force

发包遇到的错误

在这里插入图片描述
以为是重名结果改了名字还是报错
结果发现是没有验证邮箱

猜你喜欢

转载自blog.csdn.net/weixin_43881166/article/details/114883114