提交自己的包到 npm 中

npm

npm全称Node Package Manager,是node.js的模块依赖管理工具。使用github管理NPM包的代码,并定期提交至NPM服务器;
npm官网

提交自己开发的NPM包

创建package.json文件

package.json文件的使用可以让包的安装更容易,你可以在应用程序的根目录下创建一个名为 package.json 的文件,并定义它的依赖关系。使用npm init 命令来创建package.json文件:

$ npm init
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sane defaults.

See `npm help json` for definitive documentation on these fields
and exactly what they do.

Use `npm install <pkg> --save` afterwards to install a package and
save it as a dependency in the package.json file.

Press ^C at any time to quit.
name: (store.js)
version: (1.0.0)
description: Local storage localstorage package provides a simple API
entry point: (store.js)
test command: store.js
git repository: (https://github.com/jaywcjlove/store.js.git)
keywords: store.js
author: (kenny.wang <wowohoo@qq.co>)
license: (ISC) MIT
About to write to /Applications/XAMPP/xamppfiles/htdocs/git/github.com/myJS/store.js/package.json:

{
  "name": "store.js",
  "version": "1.0.0",
  "description": "Local storage localstorage package provides a simple API",
  "main": "store.js",
  "scripts": {
    "test": "store.js"
  },
  "repository": {
    "type": "git",
    "url": "https://github.com/jaywcjlove/store.js.git"
  },
  "keywords": [
    "store.js"
  ],
  "author": " <wowohoo@qq.co> (kenny.wang <wowohoo@qq.co>)",
  "license": "MIT",
  "bugs": {
    "url": "https://github.com/jaywcjlove/store.js/issues"
  },
  "homepage": "https://github.com/jaywcjlove/store.js"
}


Is this ok? (yes) yes

发布到线上

添加用户

按照提示输入用户名,密码和邮箱

npm adduser

登陆用户

按照提示输入用户名,密码和邮箱

npm login

发布

npm publish

如果不带参数,则会在当前目录下查找package.json文件,按照该文件描述信息发布;
如果指定目录,就会在指定目录下查找package.json文件
测试是否发布成功,在官网搜索一下www.npmjs.com

注: package.json 中的name不要又特殊字符哦

版本更新

修改package.json里的版本号,重新npm publish

取消发布

npm unpublish

其它命令

npm install storejs 下载使用
npm config set registry https://registry.npm.taobao.org 更换镜像地址
npm config get registry 获取镜像地址
npm dist-tag ls jslite 查看当前版本
npm dedupe 尽量压平依赖树

原文地址:https://www.cnblogs.com/frontendBY/p/5303145.html