注册npm账号

https://www.npmjs.com/signup

初始化项目

  • npm init
{
  "name": "liu-array-map",
  "version": "1.0.2",
  "description": "array map function us ts",
  "main": "./dist/liu-array-map.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [
    "typescript",
    "clover"
  ],
  "author": "Clover<liu1996clover@gmail.com>",
  "license": "MIT",
  "devDependencies": {
    "typescript": "^3.9.6"
  }
}

添加一个ReadMe.md

# My First Npm Package

## Installation

Using npm:
```
- npm i -g npm
- npm i --save liu-array-map
```

In Node.js:

```
var ArrayMap = require("liu-array-map");
var result = ArrayMap([2, 3], function (item) {
    return item * 9;
});
console.log(result);
```

:cat:

发布

  • npm publish
  • 成功后即可看到自己发到npm上的包

常见错误:

1.403错误,用的是淘宝源,切回npm官方源

npm config set registry http://www.npmjs.org

2.注册的账号邮箱未验证,权限问题导致无法发包

基本的错误百度一下都有,不再列举

https://www.npmjs.com/package/liu-array-map


爬。