I have combed the process of NPM package delivery:

1. Basic module code

Git.daojia-inc.com/eife/dj-inp…

Project description: The drop-down search box can be added on the mobile terminal

2. Register an NPM account

To publish an NPM, you need to have an NPM account and password. Go to the official website to register

Official website: www.npmjs.com/

3. Configure package.json

Create a new folder and run NPM init directly. Here are the configuration items to fill in.

{
    "name": "dj-input-search"."version": "1.0.0"."description": "Mobile inputable drop-down search box"."scripts": {
        "test": "echo \"Error: no test specified\" && exit 1"
},
    "dependencies": {},
    "devDependencies": {
        "css-loader": "^" 1.0.1."file-loader": "^ 2.0.0." "."html-webpack-plugin": "^ 3.2.0"."scss-loader": "0.0.1"."style-loader": "^ 0.23.1"."vue": "^ 2.5.17"."vue-loader": "^ 15.4.2." "."vue-style-loader": "^ 4.1.2." "."vue-template-compiler": "^ 2.5.17",},"repository": {
        "type": "git"."url": "http://git.daojia-inc.com/eife/dj-input-search.git"
},
    "author": "zhuhuanhuan"."license": "ISC"
}
 
Copy the code

Note that when configuring name, go to NPM to search for the module name you want to write. If you cannot find it, you can use this name to send packets.

There is also a version number, starting with v1.0.0 by default.

NPM community version number rules use the semantic version 2.0.0, the main rule version format:

Major version. Minor version. Revision number

The rule for increasing the version number is as follows:

  • Major version number: When you make incompatible API changes,
  • Minor version number: When you make a backward-compatible feature addition,
  • Revision number: When you make a backward compatible problem fix.
  • The prior version number and version build information can be added to the major version number. Second version number. Revision number “is followed as an extension.

Here are the details of the package.json file.

  • Description: Indicates the description, which helps search
  • Main: entry file, usually index.js
  • Scripts: supported scripts, default is an empty test
  • Keywords: Keywords that help people find your project when they use NPM Search
  • Author: Indicates the author information
  • License: license
  • Bugs: Some error information about the current project, if any
  • Repository: Specifies where code is stored.

Here are two ways packages depend on each other:

  • Dependencies: Dependencies that are needed in a production environment
  • DevDependencies: Dependencies used in development and testing environments

The first dependent installation method:

npm install xxx --save
Copy the code

The second dependent installation mode:

npm install xxx --save-dev
Copy the code

To put your project into the current folder, remember to go to NPM to install the packages needed for the project.

Up to now, I can probably send the package, but it is a little rough, the readme has not written, others do not know what this package is used for.

Add a Demo case

Is a runnable use case

Perfect README. Md

It’s important that you explain what the project is for, how to use it, have a full API, have a specific example of how to use it.

release

Log in first

NPM adduser or NPM loginCopy the code

Enter account number: XXX

Password: XXX

Email: Your own email address

Execute issue command

Hint + [email protected] means the package has been issued successfully, you can search the module name you published on NPM official website.

There are several issues encountered during the release process:

1, NPM ERR! no_perms Private mode enable, only admin can publish this module:

Or the following error:

NRM use NPM // Switch the NPM source ADDRESSCopy the code

2, NPM ERR! you do not have permission to publish “your module name”. Are you logged in as the correct user?

No permission, in fact, your module name is occupied, go to NPM to search the module name, the name can be used, and need to change the package.json name.

Other operating

Cancel the contract

NPM unpublish [email protected]Copy the code

Note that if you send a package again, you need to change the version number; otherwise, an error will be reported.

Updated version number

NPM version 1.0.1Copy the code

supplement

Use of NPM link

In the module development stage, we can use the NPM link command to link the local NPM module to the project, which is convenient for development and debugging.

www.jianshu.com/p/aaa7db89a…