当前位置:网站首页>Package management tools --npm, -cnpm, -yan, -cyarn
Package management tools --npm, -cnpm, -yan, -cyarn
2022-06-22 23:47:00 【Delete your code in the middle of the night·】
Node Package Manager , Node Package manager , It's also an application .
package :Node.js The package basically follows CommonJS standard , Put together a set of related modules , Form a complete tool
effect : adopt NPM It can be done to Node Tool kit for 、 download 、 install 、 Delete 、 Upload . With the help of the bag written by others , It can make our development more convenient .
install : installed nodejs Then it will be installed automatically npm
Common commands
see npm Version of
npm -v
initialization
npm init
npm init -y # Folder name cannot be Chinese
After running, it will create package.json file
{
"name": "1-npm", # The name of the bag
"version": "1.0.0", # The version of the package
"description": "", # Package description
"main": "index.js", # Package entry file
"scripts": { # Script configuration
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "", # author
"license": "ISC" # Copyright notice
}
== Note that the generated package name cannot be in Chinese , Capitalization !!! Out of commission npm As the name of the package ==
==npm init The command is usually run in the root directory of the project , And git The command execution location is the same ==
Installation kit
npm install jquery
npm i jquery# Install and install in package.json Save package information in (dependencies attribute )
npm install jquery --save
npm install jquery -S# Install and install in package.json Save package information in (devDependencies attribute )
npm install babel --save-dev
npm install babel -D6 Version of npm , The package will be automatically saved in dependencies in , You don't have to write --save
Global installation
npm install less -g
npm install nodemon -g
Global installation is generally used to install global tools , Such as cnpm,yarn,webpack ,gulp etc. , Installation location of global commands
C:\Users\ Your username \AppData\Roaming\npm
The global installation command is available on any command line , Can be executed
Installation dependency
according to package.json Dependency declaration in , Installation kit
npm i
npm install
Remove package
npm remove jquery
Usage flow
Team development uses processes
Pull the warehouse code from the warehouse
== function npm install Installation dependent ==
Run the project , Continue to develop
encapsulation NPM package
Create your own NPM Packages can help code evolve iteratively , The steps are also relatively simple
Change to the official address (npm config set registry https://registry.npmjs.org/)
Create folder , And create files index.js, Declare a function in a file , Use module.exports expose
npm Initialize the toolkit ,package.json Fill in the package information ( The name of the package is unique )
Account registration ( Activate account ),== Complete mailbox verification ==
At the command line 『npm login』 Fill in relevant user information
At the command line 『 npm publish』 Submission package
npm There is a garbage detection mechanism , If the name is simple or do Test submission , It is likely that you will be refused to submit
== Try changing the package name to solve this problem ==
upgrade NPM package , Need modification package.json Revision of version number in , Just execute 『npm publish』 You can submit
Modify package code
modify package.json Medium version No
npm publish Submit
When others use this package , The current package needs to be upgraded , npm upgrade name Upgrade the currently used package
Delete npm package
npm unpublish Package name --force
CNPM
cnpm It's Taobao to foreign countries npm A full mirrored version of the server , That's Taobao npm Mirror image , Web site address npmmirror China mirror station
install
There are two ways to install and configure
npm install -g cnpm --registry=https://registry.npm.taobao.org
alias cnpm="npm --registry=https://registry.npm.taobao.org \ --cache=$HOME/.npm/.cache/cnpm \ --disturl=Package - dist \ --userconfig=$HOME/.cnpmrc" ( Only in Linux Next use )
Use
When the configuration is complete , You can use cnpm Command to manage packages , How to use it npm equally
cnpm install lodash
npm Configure image address
// Taobao mirror
npm config set registry https://registry.npm.taobao.org
// Official mirror image
npm config set registry https://registry.npmjs.org/
Yarn
yarn yes Facebook Open source new package manager , Can be used instead of npm.
characteristic
yarn Compared with npm There are several characteristics
Local cache . The installed package will not be installed remotely next time
Parallel download . Download multiple packages at once , and npm Is a serial download
Precise version control . Ensure that each installation is the same as the last one
install
yarn install
Just one command to install yarn
npm install yarn -g
msi Installation package installation :Installation | Yarn
Relevant command
yarn Related commands
1) yarn --version
2) yarn init // Generate package.json
3) yarn global add package ( Global installation )
4) yarn global dir View the location of the global installation
Global installation path C:\Users\ Your username \AppData\Local\Yarn\bin
4) yarn global remove less ( Global delete )
5) yarn add package ( Partial installation )
6) yarn add package --dev ( amount to npm Medium --save-dev)
7) yarn remove package remove
8) yarn list // List the installed package names Rarely used
9) yarn // install package.json All dependencies in
npm 5 Introduce offline cache , Improved installation speed , It has also been introduced. package-lock.json File enhanced version control
yarn Modify warehouse address
yarn config set registry https://registry.npm.taobao.org
CYarn
Follow npm And cnpm Same relationship , It can be for yarn Set the domestic Taobao image , Speed up installation
npm install cyarn -g --registry "https://registry.npm.taobao.org"
After the configuration , Just put the yarn Change it to cyarn Just use it
attach :
Install the specified version of the toolkit
yarn add [email protected]
npm Clear cache
npm cache clean
environment variable Path Set up
This computer -> Right click Properties
Advanced system setup
Click environment variable
double-click Path A variable's value
newly build -> Add folder path
Make sure along the way
边栏推荐
- 使用smart-doc自动生成接口文档
- OJ daily practice - Verifying substring
- 【GO】Go Modules入門
- OLAP ——Druid简介
- 剑指 Offer 07. 重建二叉树
- OJ daily practice - spanning 2020
- Problèmes rencontrés lors de l'utilisation de redistemplate
- OJ daily practice - find the first character that only appears once
- Redistemplate encountered problems with \x00
- 昆仑分布式数据库技术优势
猜你喜欢

【ARM】讯为rk3568开发板lvds屏设置横屏显示

OLAP ——Druid简介

Optimization - linear programming

Asynchronous FIFO

C sqlsugar, hisql, FreeSQL ORM framework all-round performance test vs. sqlserver performance test

考过HCIP依然转行失败,职业网工最看重的到底是什么

【GO】go mod模式, package 12import/add is not in GOROOT

swagger2 使用方法

再立云计算“昆仑”,联想混合云Lenovo xCloud凭什么?

KunlunDB查询优化(三)排序下推
随机推荐
three.js模拟驾驶游览艺术展厅---打造超级相机控制器
Synchronization circuit and cross clock domain circuit design 2 -- cross clock domain transmission (FIFO) of multi bit signals
RedisTemplate使用遇到\x00的問題
Flutter outsourcing, undertaking flutter project
OLAP ——Druid简介
DML:Data Manipulation Language 数据操纵语言
RedisTemplate使用遇到\x00的问题
考过HCIP依然转行失败,职业网工最看重的到底是什么
剑指 Offer 07. 重建二叉树
MySQL8.0轻松完成GTID主从复制
Redis缓存
Array and string offset access syntax with curly braces is no longer support
After passing the hcip exam, I still failed to change my career. What do professional network workers value most
Array and string offset access syntax with curly braces is no longer support
OJ daily practice - sorting and naming
剑指 Offer 05. 替换空格
Redistemplate encountered problems with \x00
Express、路由(Route)、Request对象、Response对象、中间件、EJS模板
ECMAScript6新特性
ES5 Object的扩展方法//call、apply 和 bind