Especially suitable for xiaobai reading, especially the introduction of NPM is especially good

Come on, here.

It looks something like this

Introduction of NPM

NPM is the Node.js standard package manager.

As of January 2017, there were more than 350,000 packages in the NPM repository, making it the largest single-language code repository in the world, and there are certainly packages available for just about anything.

It was originally used as a way to download and manage node.js package dependencies, but it has also become a tool used in front-end JavaScript.

NPM has many functions.

Yarn is an alternative to NPM.

download

NPM can manage downloads that project depends on.

Install all dependencies

If your project has a package.json file, run:

npm install
Copy the code

It installs everything the project needs in the node_modules folder (created if it doesn’t already exist).

Installing a Single Software Package

You can also install specific packages by running the following command:

npm install <package-name>
Copy the code

You’ll usually see more flags in this command:

  • --saveInstall and add entries topackage.jsonFile dependencies.
  • --save-devInstall and add entries topackage.jsonThe file devDependencies.

The main difference is that devDependencies are usually a development tool (such as a library for testing), whereas Dependencies are related to an application in a production environment.

Updating software Packages

Updates are also made easy by running the following command:

npm update
Copy the code

NPM checks all packages for newer versions that meet version limits.

You can also specify a single package to update:

npm update <package-name>
Copy the code

Version control

In addition to simple downloads, NPM also manages version control, so you can specify any particular version of a package, or require a version higher or lower than the required version.

Many times, a library is only compatible with the main version of another library.

Or, a bug (still unfixed) in the latest version of a library causes problems.

Specifying an explicit version of the library also helps to keep everyone using the same package version so that the entire team can run the same version until the package.json file is updated.

In all of these cases, versioning helps a lot, and NPM follows semantic versioning standards.

Run the task

The package.json file supports a format for specifying command line tasks that can be run using:

npm run <task-name>
Copy the code

Such as:

{
  "scripts": {
    "start-dev": "node lib/server-development"."start": "node lib/server-production"}},Copy the code

It is common to run Webpack using this feature:

{
  "scripts": {
    "watch": "webpack --watch --progress --colors --config webpack.conf.js"."dev": "webpack --progress --colors --config webpack.conf.js"."prod": "NODE_ENV=production webpack -p --config webpack.conf.js",}}Copy the code

So instead of typing long commands that are easily forgotten or mistyped, you can run the following:

$ npm run watch
$ npm run dev
$ npm run prod
Copy the code

Go and see