开发npm模块

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
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容