Mirror address: use PNPM instead of YARN

PNPM advantages needless to say, understand natural know that don’t understand, went to the website to see their introduction project purpose | PNPM here the main purpose is to use the PNPM replace yarn and NPM

  • NPM is the package management tool for Node, so my understanding is that Node is the foundation and NPM must have node
  • Yarn is a package of NPM. NPM is required before yarn can be used
  • However, node versions can also be switched. In this case, NVM is used when switching nodes, and NVM depends on NPM and YARN.

The dependency cycle caused by this can not escape the cycle, will lead to more things related

After I understand PNPM, it can solve the above problems well and has its own unique advantages

  • Clean installation, based on BREW
  • Manages nodes globally and supports automatic installation
  • Package management uses soft links to avoid the need for repeated downloads between multiple projects to occupy disk space

So we decided to use it to replace NVM, YARN, and NPM with just one tool

The backup

# NVM version and installation location $NVM ls... V16.13.2 v16.14.1 - > v16.14.2 $which node/Users/duoli/NVM/versions/node/v16.14.2 / bin/node and global command $# yarn position which yarn /Users/duoli/.yarn/bin/yarn $ which browser-sync / Users/duoli/config/yarn/global/node_modules/bin/browser - the position of the sync # NPM $which NPM / Users/duoli. NVM/versions/node/v16.14.2 / bin/NPMCopy the code

To satisfy my curiosity, I took a look at the space used

$ du -h -d 1 /Users/duoli/.nvm ... 1.3 G/Users/duoli/NVM $du - h - 1 / Users/d duoli /. Config/yarn... 598M /Users/duoli/.config/yarn $ du -h -d 1 ~/.yarn ... 5.1 M/Users/duoli/yarnCopy the code

To back up the global command of the current installation, I use YARN

. $cat ~ / config/yarn/global/package. The json {" dependencies ": {" @ js - lib/cli" : "^ 1.6.0", "@ tarojs/cli" : "^ rule 3.4.3 apidoc", ""," ^ 0.50.5 ", "bower" : "^ 1.8.14", "browser - sync" : "^ 2.27.9", "but - changelog" : "^ 3.1.25 but - changelog -", "cli" : "^ 2.2.2", "cross - env" : "^ 7.0.2", "jsdoc" : "^ 3.6.10", "NRM" : "^ 1.2.1", "PNPM" : "^6.32.3", "typescript": "^4.6.2"}}Copy the code

The above backup is complete with about 1.9 GIGABytes of space, including many unused Node versions starting from version 14.

Clean up the

Clear the installed commands

$ yarn global remove @js-lib/cli .....
Copy the code

If this is not done, the NVM.zshrc file will be used to remove the configuration

# nvm & node
# export NVM_DIR="$HOME/.nvm"
# [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
# [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

# yarn
# export PATH="$HOME/.yarn/bin:$HOME/.config/yarn/global/node_modules/.bin:$PATH"
Copy the code

After clearing the command, restart the cli. Otherwise, the path is still in the terminal.

The installation

The commands and Spaces mentioned above will be removed after installation

Install and configure the environment

Install PNPM globally

$ brew install pnpm
Copy the code

Set the global bin location and add environment variables

$ pnpm config set global-bin-dir ~/.pnpm-store/bin
Copy the code

Add environment variables and enable them

$ vim ~/.zshrc
Copy the code

Add the following line

export PATH="$HOME/.pnpm-store/bin:$PATH"
Copy the code

To enable the

$ source ~/.zshrc
Copy the code

Use the LTS version of Node

$ pnpm env use --global lts
Copy the code

Install the NRM

Here, NRM will be installed first, and the subsequent installation will be faster after Taobao image is enabled

$ pnpm install -g pnpm
$ which nrm
/Users/duoli/.pnpm-store/bin/nrm
Copy the code

Here the NRM command will be installed in the directory we set, and the global command will be installed later, mainly for the purpose of comparing package sizes

pnpm install -g @js-lib/cli pnpm install -g @tarojs/cli pnpm install -g apidoc pnpm install -g bower pnpm install -g browser-sync pnpm install -g conventional-changelog pnpm install -g conventional-changelog-cli pnpm install -g cross-env  pnpm install -g jsdoc pnpm install -g nrm pnpm install -g pnpm pnpm install -g typescriptCopy the code

Check the size

$ du -d 1 -h /Users/duoli/.pnpm-store
 68K	/Users/duoli/.pnpm-store/bin
697M	/Users/duoli/.pnpm-store/v3
697M	/Users/duoli/.pnpm-store/
Copy the code

Check the size of the node

$ du -d 1 -h /Users/duoli/Library/pnpm
592M	/Users/duoli/Library/pnpm/nodejs
592M	/Users/duoli/Library/pnpm
Copy the code

The overall size of 1.3g, of course, there are multiple versions, for public files, the impact is not particularly big, but its advantage lies in the soft link of multiple files, we use the project and then compare

Clean up the

Clear yarn, NVM, and soft links

Yarn $YARN Global remove... $ rm -rf ~/.nvmCopy the code

So far, toss over and over, see what problems to meet later to add