npm init
初始化npm模块
npm init
package.js
{
"name": "npmfunc",
"version": "1.0.1",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "hwj",
"license": "ISC",
"dependencies": {
"npmfunc": "^1.0.1"
}
}
index.js
function debounce(func,wait) {
let timer = null
return function() {
if(timer) {
clearTimeout(timer)
}
timer = setTimeout(()=> {
func.apply(this,arguments)
},wait)
}
}
export {
debounce
}
npm link
将npm 模块链接到对应的运行项目中去,方便地对模块进行调试和测试
npm link
npm login
登录npm账号
npm login
npm publish
上传至npm
npm publish