- Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”.
The introduction
- Whether you’re a developer on the front end, back end, or elsewhere,
npm
和yarn
Package management tools are essential for daily development, so what are some of the commands we use?
The statement
[package] === [package] | [package]@[version|tag]
Copy the code
The installation
General installation
npm
- throughNode.jsOfficial website, download and install
Node
Will automatically installnpm
.
- throughNode.jsOfficial website, download and install
yarn
- through
npm
The installationyarn
.
npm install -g yarn Copy the code
- through
Prompt ⚠ ️ :npm
中 install
I can write it as thetai
.
other
- Windows installation yarn
- Mac installation of yarn
Viewing the Current Version
npm|yarn -v
// or
npm|yarn --version
Copy the code
Update the package management tool itself
npm
- Update Latest version
NPM install -g npm@latest // Requires root permissionCopy the code
- Install future releases
npm install -g npm@next
Copy the code
yarn
- Update Latest version
yarn global upgrade yarn
// mac
curl --compressed -o- -L https://yarnpkg.com/install.sh | bash
Copy the code
Global related
configuration
- To view
npm|yarn config list
Copy the code
- delete
npm config delete [typename]
Copy the code
Global package
- The installation
npm install -g [package]
yarn global add [package]
Copy the code
Prompt ⚠ ️ :yarn
中 global
Must followyarn
After.
- update
npm update -g [package]
yarn global upgrade [package]
Copy the code
- To view
npm list -g --depth 0
yarn global list
Copy the code
Global mirror source
- To view
npm|yarn config get registry
Copy the code
- Modify the
NPM | yarn config set registry [origin]Copy the code
- delete
/ / 1. Command NPM | yarn config delete registry / / 2. Find.npmrc file delete Windows C:\Users\[username] Mac ~Copy the code
In the project
Initialize thepackage.json
npm|yarn init
Copy the code
The installation package
- Specify a name
npm install [package] --save-dev
yarn add [package] --dev
Copy the code
package.json
An existing package in
npm install yarn ? [install]Copy the code
- instructions
npm
--save === -S
: installed in thepackage.json
的dependencies
In the.--save-dev === -D
: installed in thepackage.json
的devDependencies
In the.
yarn
--save === -S
: installed in thepackage.json
的dependencies
In the.--dev === -D
: installed in thepackage.js
的devDependencies
In the.--peer
: installed in thepackage.json
的peerDependencies
In the.--optional
: installed in thepackage.json
的optionalDependencies
In the.
dependencies
和devDependencies
The difference betweendependencies
: Project (run, release to production) dependenciesdevDependencies
: Engineering build (development, packaging) dependencies.
Update package
npm update [package]
yarn upgrade [package]
Copy the code
Delete the package
npm uninstall [package] --save? -dev yarn remove [package]Copy the code
View installed packages
NPM list yarn list --depth=0 // --depth=0 Does not display package dependenciesCopy the code
The development ofnpm
包
The loginnpm
npm|yarn login
Copy the code
npm
The official website cannot be logged in (forget password and2FA
), can passConcat npmcontactnpm
Official, choiceI need help with something / I have account or billing issue
.
Local test
- Development kit projects
npm|yarn link
Copy the code
- Test package project
NPM | yarn link/package/run/package development package yarn link after the name of the showCopy the code
- uninstall
/ / development kit project NPM | yarn unlink/project/test package NPM | yarn unlink [package] / run/package development package yarn display name after the linkCopy the code
release
NPM | yarn publish - tag < tag > / / specific label yarn add XXX @ beta NPM | yarn publish - access < public | restricted > / / release for limited public package or packagesCopy the code
More orders
- NPM Chinese document
- Yarn Chinese document
- Set up the proxy for NPM
Past wonderful
- Gold nine front-end interview summary!
- Basic specifications for front-end development
- Build from 0 Vite + Vue3 + element-plus + VUE-Router + ESLint + husky + Lint-staged
- “Front-end advanced” JavaScript handwriting methods/use tips self-check
- Public account open small program best solution (Vue)
- Axios you probably don’t know how to use
“Likes, favorites and comments”
❤️ follow + like + comment + share ❤️, lingering fragrance in hand, thank 🙏 everyone.