NPM study notes (a)

NPM:
  node Package Penalty for Manager, Administration Tools node packages. Written using Node.js, before using the need to install Node.js.

 

NPM installation

  Method one: Install Node.js (LTS version), will install npm

  Method two: Install Node.js and npm by NVM (Node Version Manage, Node Manager Version)

 

package.json file

  • Lists the project depends Packages
  • Version allows the use of "semantic versioning rules" rule specifies that projects can use the package
  • The building can be copied, easier to share with other developers

  Claim:

    A package.json file must have:

  • "name"
    • Only lowercase letters
    • At least one word, no spaces
    • Allows the use of dashes and underscores
  • "version"
    • The format xxx
    • Follow semver specification

  create:

    Method 1: npm init (to inquire about the way in order to initialize the configuration items)

    Second way: npm init --yes or npm init -y (generating current directory information from the default value in advance)

  note:

    If no value is set "description" of, npm README.md using the first line of the file as the value. (To facilitate searches on the npm)

  Set several configuration options to init command:

    npm set init.author.email "[email protected]"

    npm set init.author.name "uakora"

    npm set init.license "MIT"

  Since the problem of the definition of package.json initialization file: Create a custom file npm-init.js file in your home directory ...

  

  Specify dependencies:

  • "Dependencies": software package for the production environment
  • "DevDependencies": software package for development and testing

  --save 和 --save-dev:

    npm install <package_name> --save (write only "dependencies", the same default)

    npm install <package_name> --save-dev (write only "devDependencies" in)

package

Installation package  

  npm install [-g] <package_name>  

  • If the module is dependent on a bag, and loaded by require Node.js, then you should choose local installation
  • If you want to package as a command-line tool, such as grunt CLI, you should select a global installation

  Description: After executing the above command will create a directory node_modules in the directory (if it does not exist)

Update package

  npm update [-g]  [package_name]

  Description:

    1. do not specify a package name, will be updated all packages

    2. Before the update, can be outdated by performing npm [-g] View A new version of the package

    3. npm outdated -g --depth = 0 (see the need to update the package)

Uninstall package

  npm uninstall [-g] [package_name]

  Description:

    1. When using npm 6.13.4 version, no need to add --save or --save-dev argument, package.json is dependent also deleted at the same time.

Release package

  Step one: Log: npm login (not have an account, you must first create an account npm adduser)

  Step two: Test is logged: npm whoiam (non-essential)

  Step three: Make sure the package is correct

  Step Four: Published: npm publish

  Released its own update package:

    Updated version: npm version <update_type>

    Update README.md file: npm version patch

    The last execution npm publish

Guess you like

Origin www.cnblogs.com/uakora/p/12045238.html