发布NPM包

包目录结构:必须包含index.js,package.json,README.md三个文件

在这里插入图片描述

index.js 这里写自己要是显得功能然后module.exports暴露出去

// 这是包的入口文件
const date = require('./src/dateFormat')
const escape = require('./src/htmlEscape')


module.exports = {
    ...date,
    ...escape
}

package.json 这是包的信息

{
  "name": "luffy-tools",
  "version": "1.0.0",
  "description": "提供了格式化时间,HTMLEscape的功能",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": ["luffy","dateFormat","escape"],
  "author": "luffy",
  "license": "ISC"
}

README.md里面写描述:安装,导入,和使用

安装

npm install luffy-tools

导入

const luffy = require('luffy-tools')

格式化时间

// 调用 dateFormat 对时间进行格式化
const dtStr = luffy.dateFormat(new Date())
// 结果 2020-04-03 17:20:58
console.log(dtStr);

发布

控制台操作:

npm login
//进行登录
cd luffy-tools
//cd 到要发布的包
npm publish
//发布

删除已发布的包

npm unpublish luffy-tools --force

NPM官网

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值