当前位置:网站首页>Yarn common commands

Yarn common commands

2022-07-05 16:41:00 Pan Sidong

yarn install

npm i yarn -g

View version

Yarn -v

1. Start a new project

yarn init And npm init Create an interactive session package.json

yarn init # yarn

npm init # npm

Skip session , Generate directly by default package.json

yarn init --yes # Abbreviation -y

npm init -y

2. Add a dependency

adopt yarn add Adding a dependency updates package.json as well as yarn.lock file

1). development environment

yarn add Dependence will be recorded in package.json Of dependencies Next development environment

yarn add [email protected] # yarn --save yes yarn default , Default record in package.json in

npm install [email protected] --save # npm

2). Production environment

yarn add --dev Dependence will be recorded in package.json Of devDependencies Next Production environment

yarn add webpack --dev # yarn Abbreviation -D

npm install webpack --save-dev # npm

3). overall situation

yarn global add Global installation depends on

yarn global add webpack # yarn

npm install webpack -g # npm

3. Update a dependency

yarn upgrade Used to update packages to the latest version based on specification scope

yarn upgrade # Upgrade all dependencies , Not recorded in package.json in

npm update # npm Can pass ‘--save|--save-dev’ Specify which type of dependency to upgrade

yarn upgrade webpack # Upgrade the specified package

npm update webpack --save-dev # npm

yarn upgrade --latest # Ignore version rules , Upgrade to the latest version , And update package.json

4. Remove a dependency

yarn remove

yarn remove webpack # yarn

npm uninstall webpack --save # npm You can specify --save | --save-dev

5. install package.json All files in

yarn perhaps yarn install

yarn install # perhaps yarn stay node_modules Directory installation package.json All dependencies listed in

npm install # npm

yarn install When installing , If node_modules If there is a corresponding package in, it will not be downloaded again --force You can force the download and installation again

yarn install --force # Forced download and installation

npm install --force # npm

6. Run script

yarn run Used to perform the package.json in scripts Property

// package.json

{

"scripts": {

"dev": "node app.js",

"start": "node app.js"

}

}

yarn run dev # yarn perform dev The corresponding script node app.js

npm run # npm

yarn start # yarn

npm start # npm

And npm equally There can be yarn start and yarn test Two short ways to run scripts

7. Display a package information

yarn info It can be used to view the latest version information of a module

yarn info webpack # yarn

npm info webpack # npm

yarn info webpack --json # Output json Format

npm info webpack --json # npm

yarn info webpack readme # Output README part

npm info webpack readme

8. List all dependencies of the project

yarn list

yarn list # List the dependencies of the current project

npm list # npm

yarn list --depth=0 # Limit the depth of dependency

sudo yarn global list # Lists the modules installed globally

9. management yarn The configuration file

yarn coinfig

yarn config set key value # Set up

npm config set key value

yarn config get key # Read the values

npm config get key

yarn config delete key # Delete

npm config delete key

yarn config list # Show current configuration

npm config list

yarn config set registry https://registry.npm.taobao.org # Set Taobao image

npm config set registry https://registry.npm.taobao.org # npm

10. cache

yarn cache

sudo yarn cache list # List each package that has been cached

sudo yarn cache dir # return Global cache location

sudo yarn cache clean # Clear cache

原网站

版权声明
本文为[Pan Sidong]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/186/202207051546328869.html