What is NPM series: two, install eighteen martial arts
NPM install is not only used to install NPMJS packages, but also can be installed directly from Git and Gitlab. Let’s take a look at the parameters of the install command:
NPM install NPM install [<@scope>/]<name> NPM install [<@scope>/]<name>@<tag> NPM install [<@scope>/]<name>@<version> NPM install [<@scope>/]<name>@<version range <git-host>:<git-user>/<repo-name> npm install <git repo url> npm install <tarball file or url> npm install <folder>Copy the code
1. npm install
By default, all modules listed in package.json are installed after the command is executed.
If the –production tag is added, or the environment variable NODE_ENV is set to production, NPM will not install modules in devDependencies.
1.1 npm install <folder>
The package directory is connected to the project through a symlink.
1.2 npm install <tarball file or url>
There are two ways to wrap from tar:
- File: indicates the local tar file
npm install ./package.tgz
Copy the code
- Url: The address of the remote tar
NPM install https://github.com/indexzero/forever/tarball/v0.5.6Copy the code
1.3 npm install <git remote url>
Another common way to install NPM packages is from a Git address, but you need to be careful whether the repository is too large or if the source address is in a foreign country, which can affect the installation speed.
The protocol address format is as follows:
<protocol>://[<user>[:<password>]@]<hostname>[:<port>][:][/]<path>[#<commit-ish> | #semver:<semver>]
Copy the code
If #
or #semver:
is configured, NPM will install the matched commit, otherwise it will use the master branch.
When installing modules with Git, there are access issues, and we can use the following environment variables:
GIT_ASKPASS
GIT_EXEC_PATH
GIT_PROXY_COMMAND
GIT_SSH
GIT_SSH_COMMAND
GIT_SSL_CAINFO
GIT_SSL_NO_VERIFY
Copy the code
For a detailed introduction to environment variables, see this: Git Internals – Environment variables
Another stupid way is to use SSH to install. After configuring the SSH key on the local computer, you can directly verify the permission.
The following is an example:
npm install 'git+ssh://[email protected]: ineo6 / mini - deploy. Git # v1.0.2'
npm install 'git+ssh://[email protected]: ineo6 / mini - deploy# semver: ^ 1.0'
npm install 'git+https://[email protected]/ineo6/mini-deploy'
npm install 'git://github.com/ineo6/mini-deploy#v1.0.2'
GIT_SSH_COMMAND='ssh -i ~/.ssh/custom_ident' npm install 'git+ssh://[email protected]:ineo6/mini-deploy.git'
Copy the code
1.4 npm install <githubname>/<githubrepo>[#<commit-ish>]
If our code is hosted on Github, we can install it with a shorter command:
- npm install
<githubname>/<githubrepo>[#<commit-ish>]
- npm install
github:<githubname>/<githubrepo>[#<commit-ish>]
The following is an example:
npm install ineo6/magic-lint
npm install github:ineo6/magic-lint
Copy the code
1.5 Install from Github Gist
The command is as follows:
npm install gist:[<githubname>/]<gistID>[#<commit-ish>|#semver:<semver>]
Copy the code
The content of https://gist.github.com/gistID for the installation package, it is important to note gist need a ladder to access the content.
The following is an example:
npm install gist/1b91123bccc1bb3509bccdbe15215c83
Copy the code
1.6 Installing from bitbucket
Install the hosting package on https://bitbucket.org/bitbucketname/bitbucketrepo.
The command is as follows:
npm install bitbucket:<bitbucketname>/<bitbucketrepo>[#<commit-ish>]
Copy the code
The following is an example:
npm install bitbucket:mybitbucketuser/myproject
Copy the code
1.7 Installation from GitLab
Install the hosting package on https://gitlab.com/gitlabname/gitlabrepo.
The command is as follows:
npm install gitlab:<gitlabname>/<gitlabrepo>[#<commit-ish>]
Copy the code
The following is an example:
npm install gitlab:mygitlabuser/myproject
npm install gitlab:myusr/myproj# semver: ^ 5.0
Copy the code
2. Add parameters
When using NPM install, we can use a mix of parameters:
— Tag corresponds to dist-tag (found invalid in actual execution)
Dry-run is a simulation run that outputs only logs and does not perform the actual installation.
–package-lock-only Only updates package-lock-. json without installing dependencies.
-for –force Forcibly installs remote resources
-g or –global Global installation
–global-style When a local dependency is installed, the directory format is the same as the global one
–ignore-scripts ignore the scripts in package.json
Legacy – Bundling NPM installation mode will revert to nested installation
–link Installs the global package locally as a soft link (more on this later)
–no-bin-links Avoids creating symlinks for binary execution files in packages
–no-optional Avoids optional dependencies being installed
– no – shrinkwrap shrinkwrap ignored
– no – package – lock ignore package – lock. Json
–nodedir=/path/to/node/source Specifies the node directory
– only = {prod uction] | dev elopment]} is equivalent to NODE_ENV, install only the devDependencies dependence or devDependencies dependency
–no-audit Disables diagnostic reporting
We can add two more arguments to the above argument:
- -e, –save-exact: Version number will not be recorded semantically, it will show the specific “1.2.3”
- -b, –save-bundle: dependencies are also logged in
bundleDependencies
In the
4. The forecast
Publish your own NPM package under the title of the next article, focusing on the release process and the points to pay attention to, but also a lot of dry goods waiting to be discovered.
Series of summary
- What is the NPM series
- What is the NPM series: two, install eighteen martial arts
- to be continued