In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Editor to share with you what skills to use NPM, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
Here are some tips for using NPM as a tool.
Npmrc
As a configuration file for npm, .npmrc can be defined in multiple places.
~ / .npmrc
User root directory, and all npm instructions in the root directory will query the configuration.
/ path/to/npm/npmrc
Npm built-in profile
. / .npmrc
The current project root directory, which is used to configure configurations specific to the current project
Npmrc is very useful to us, and we can configure information such as username, registry, email, and so on. Eg:
Save=true save-exact=true email=wfsovereign@outlook.com username=wfsovereign registry= https://registry.npm.taobao.org
One of the most troublesome problems with npm is the version number, where the save and save-exact attributes are configured to automatically save the dependencies installed by our npm install directive in the dependencies of the package.json file and keep the version number fixed.
Some domestic servers often fail or are slow to pull some walled packets. At this time, we can try Taobao NPM image (this is a full npmjs.org image, which you can use instead of the official version (read-only). The synchronization frequency is currently 10 minutes to ensure synchronization with the official service as much as possible. Officials have also customized cnpm, which depends on the situation. For example, I once had a project deployed on Microsoft's Asure, and this server felt badly walled. If I was lucky to use the zip file of phantomjs under the official npm library, I had to download it two or three times. Later, I tried Taobao image to solve this problem, but the problem was that I used cnpm, and the package pulled by cnpm could not be compiled locally. Later, I switched back to npm and used Taobao image. Everything worked fine.
Package.json
Package.json is the configuration management file of the project, which defines the dependent modules required by the project and the configuration information of the project (name, version number, license, etc.). A basic package.json must have name and version, something like this:
{"name": "xxx", "version": 0.0.0}
We can initialize and create a package.json file with the npm init instruction
{"name": "test", "version": "1.0.0", "description": "," main ":" index.js "," scripts ": {" test ":" echo\ "Error: no test specified\" & & exit 1 "}," author ":" wfsovereign "," license ":" ISC "," devDependencies ": {}," dependencies ": {}
The following attributes are described
Scripts
Scripts defines some npm command abbreviations for script instructions, through which we can easily start a project, test, or get some hooks to do what we do in advance of certain instructions.
"scripts": {"pretest": "echo\" this is pretest\ "," test ":" echo\ "Error: no test specified\"," posttest ":" echo\ "this is posttest\"}
When we execute npm test, we get the following output:
This is pre test test@1.0.0 test echo "Error: no test specified" Error: no test specified test@1.0.0 posttest echo "this is posttest" this is posttest
Through the above experiment, we can know that the prexx instruction is a pre-execution instruction and postxx is a post instruction, both of which are strongly related to the xx instruction.
Main
Main specifies the entry file loaded by the project. The default is the inde.js of the root directory.
File
File is an array of strings that specifies which files in the current directory should be included in the package we release, which is useful when we release the package, because not all the folders in the package need to be published. Of course, the file will always be included, whether we set it or not.
Package.json README CHANGES / CHANGELOG / HISTORY LICENSE / LICENCE NOTICE The file in the "main" field
Keywords
Keywords specifies which keywords can be found when searching in the library, so usually this will write more project-related words here, which is an array of strings.
For more information on the remaining attributes, please refer to the official documentation.
Semantic version
With regard to the semantic version number, I won't say much here, but put some preference.
Npm semver Gravatars semver
Some of the most common version logos (*, ~, ^) in Nodejs projects often forget their meaning. Record them here:
* any version
1.0.0 install the specified version 1.0.0
Lodash: 4.7.0 will install the exact 4.7.0 to our node_module directory
~ 1.0.0 installation > = 1.0.0 less than 1. (0 + 1) .0 version
^ 1.0.0 installation > = 1.0.0 is less than (1 + 1) .0.0
Package publish
How do I publish a package?
Npm addUser enters the account password as prompted to create a npm account. If you already have an account, go directly to the next step.
Npm whoami looks at the current user and confirms that the package is published using the current user
Npm publish can then be released directly. Of course, all kinds of problems may arise at this time, such as your package and other people's duplicate names, or the version number of the current package has been released, and so on.
When it comes to releasing packages, here are some tips for developing packages.
We can't avoid some debugging when we develop the package, but we don't want it to be released and we want to make sure that the current functionality is available, so there are two ways to help us solve this problem.
Npm link
For more information about npm link, we can take a look at the official website. Here are three uses:
Use it directly in the home directory of our development package, which is equivalent to a symbolic link to the current package in the npm global directory.
Npm link package-name, which is equivalent to putting a globally installed package link into node_module under our current directory.
Use the following declaration in the dependencies of the package.json file, and then install and use it as if you were using a package that has been normally released.
"dependencies": {"bar": "file:../foo/bar"} these are all the contents of this article entitled "what are the tips for using NPM?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.