This article is shared from Huawei Cloud Community "The relationship between npm install -g and npm install --save-dev" , author: SHQ5785.
1. npm install local installation
- Place the installation package under ./node_modules (the directory where the npm command is run). If there is no node_modules directory, the node_modules directory will be generated in the directory where the npm command is currently executed.
- Local installation packages can be introduced through require().
2. npm install -g global installation
- Place the installation package under /usr/local or the node installation directory.
- Can be used directly from the command line.
3. npm install --save
- The build package will be installed into the node_modules directory;
- Build will be added under the dependencies attribute of package.json;
- When you run the npm install command later, the build will be automatically installed into the node_modules directory;
- When you later run npm install --production or indicate that the NODE_ENV variable value is production, msbuild will be automatically installed in the node_modules directory;
4. npm install --save-dev
- The msbuild package will be installed into the node_modules directory;
- msbuild will be added under the devDependencies attribute of package.json;
- When you run the npm install command later, msbuild will be automatically installed into the node_modules directory;
- When you later run npm install --production or indicate that the NODE_ENV variable value is production, msbuild will not be automatically installed in the node_modules directory;
5. The difference between dependencies and devDependencies in package.json
- dependencies:
Packages that the application depends on for normal operation. This kind of dependencies is the most common. Users will automatically install these dependencies when using npm install to install packages.
- devDependencies:
Toolkits relied on when developing applications. Usually some development , testing , and packaging tools, such as webpack, ESLint, and Mocha. The normal operation of the application does not depend on these packages, and users will not install these dependencies when using npm install to install packages.
- peerDependencies:
Host packages that the application depends on for running . The most typical ones are plug-ins , such as various jQuery plug-ins. These plug-ins themselves do not contain jQeury and need to be provided externally. This dependency will be automatically installed when users use npm 1 or 2. npm 3 will not install it automatically and will prompt the user to install it.
- bundledDependencies:
Dependencies that need to be packaged when publishing a package seem to be rare.
- optionalDependencies:
Optional dependencies. This dependency is not necessary for the program to run, but there may be new functions after installation, such as an image decoding library. After installing optionalDependencies, more formats will be supported.
So what is the difference between the devDependencies and dependencies objects in the package.json file?
The plug-ins in devDependencies (such as various loaders, babel family buckets and various webpack plug-ins, etc.) are only used in the development environment, not in the production environment, so they do not need to be packaged; dependencies need to be released to the production environment and must be packaged. .
Click to follow and learn about Huawei Cloud’s new technologies as soon as possible~
The pirated resources of "Qing Yu Nian 2" were uploaded to npm, causing npmmirror to have to suspend the unpkg service. Zhou Hongyi: There is not much time left for Google. I suggest that all products be open source. Please tell me, time.sleep(6) here plays a role. What does it do? Linus is the most active in "eating dog food"! The new iPad Pro uses 12GB of memory chips, but claims to have 8GB of memory. People’s Daily Online reviews office software’s matryoshka-style charging: Only by actively solving the “set” can we have a future. Flutter 3.22 and Dart 3.4 release a new development paradigm for Vue3, without the need for `ref/reactive `, no need for `ref.value` MySQL 8.4 LTS Chinese manual released: Help you master the new realm of database management Tongyi Qianwen GPT-4 level main model price reduced by 97%, 1 yuan and 2 million tokens