Publish a simple package npm

Herein simply publish a simple record of the npmpackage the process for subsequent reference.

Initialization npm init

By npm initcreating a package.jsonfile

D:\robin\lib\weapp-utils>npm init
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sensible defaults.

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

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

Press ^C at any time to quit.
package name: (weapp-utils)
version: (1.0.0)
description: some foundmental utils for weapp
entry point: (lib/index.js)
test command:
git repository:
keywords: weapp,utils
author: tusi666
license: (ISC) MIT
About to write to D:\robin\lib\weapp-utils\package.json:

{
  "name": "weapp-utils",
  "version": "1.0.0",
  "description": "some foundmental utils for weapp",
  "main": "lib/index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [
    "weapp",
    "utils"
  ],
  "author": "tusi666",
  "license": "MIT"
}

Wherein the mainfield is an entry file

Written README

A complete READMEfile is necessary, so that others understand your bag is doing what purposes.

Confirm registry

Generally, we will modify the development npm registryis https://registry.npm.taobao.org.

But released npmwhen the package, we need to change it back, or is being given in.

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

npm registered account

Open npmofficial website , start the registration account.

ps: remember to verify the mailbox Oh!

Add npm Account

Use npm adduserAdd Account, Aliasnpm login

D:\robin\lib\weapp-utils>npm adduser
Username: tusi666
Password:
Email: (this IS public) [email protected]
Logged in as tusi666 on https://registry.npm.taobao.org/.

Add github repository

In package.jsonadd configuration items, without all right, look at their own needs.

"repository": {
  "type": "git",
  "url": "https://github.com/xxx/zqh_test2.git"
}

release

npm publish

If you publish this wrong Times,

The operation was rejected by your operating system.
npm ERR! It's possible that the file was already in use (by a text editor or antivirus),
npm ERR! or that you lack permissions to access it.

Under recommendations or check registry, or npm adduserwas not successful.

Release success, there will be such a prompt,

npm notice
npm notice package: [email protected]
npm notice === Tarball Contents ===
npm notice 397B   package.json
npm notice 1.1kB  LICENSE
npm notice 2.7kB  README.md
npm notice 12.9kB lib/index.js
npm notice === Tarball Details ===
npm notice name:          weapp-utils
npm notice version:       1.0.0
npm notice package size:  5.1 kB
npm notice unpacked size: 17.1 kB
npm notice shasum:        a7f2f428d9334dd1dd749d2a492dbc4df7195d0d
npm notice integrity:     sha512-Cp8jPhOMq73y6[...]bfofe7X+4cLeg==
npm notice total files:   4
npm notice
+ [email protected]

The npmsearch weapp-utils, have found!

npm query to the package released

transfer

Released succeeds, the next must verify whether normal use.

import { merge } from "weapp-utils"

let mergedOptions = merge(DEFAULT_OPTIONS, options)

Starting link


Sweep the applet code below or search Tusi博客instantly read the latest articles!

Tusi blog

Guess you like

Origin www.cnblogs.com/wenbinjiang/p/11563303.html