richardmyu / blog

个人(issues)博客
https://github.com/richardmyu/blog/issues
MIT License
0 stars 0 forks source link

js 包管理器 #24

Open richardmyu opened 3 years ago

richardmyu commented 3 years ago

最近看到文章 关于现代包管理器的深度思考——为什么现在我更推荐 pnpm 而不是 npm/yarn?,了解到一个新的包管理器 pnpm,感觉很像 npm 呀,是一家人吗?还有一个 cnpm 啥的,看来有必要做一个包管理器的小结了。


犹记得初次接触到包管理器,就是 npm,那时候真是一言难尽,印象最深的是,本来只想安装某个包,npm install xxx 以后,提示安装了十几个包,然后移除了二三十个包...

后来接触到了 cnpmyarn,但也不是没有问题,到最后,用得最久的还是 npm 😄 😄 😄。


更具体来说,是 node.js 的包管理器的一个整理,至于优缺点,此处不表。

richardmyu commented 3 years ago

npm

npm 是 Node.js 标准的软件包管理器。它起初是作为下载和管理 Node.js 包依赖的方式,但其现在也已成为前端 JavaScript 中使用的工具[1]

npm 由三部分组成 [^ 2 ]:


1.npm 包管理器简介 [^ 2 ]: About npm

richardmyu commented 3 years ago

yarn

Yarn 是 npm 的一个替代选择[1]

Yarn 的目标就是解决团队使用 npm 的时候所遇到的几个问题,即[2]

但是,不必慌张!它并不是想要完全替代 npm。Yarn 仅仅是一个能够从 npm 仓库获取到模块的新的 CLI 客户端。


1.npm 包管理器简介 2.Yarn vs npm: Everything You Need to Know

richardmyu commented 3 years ago

cnpm

cnpm: npm client for China mirror of npm[1]


1.cnpm

richardmyu commented 3 years ago

nvm / nvm-windows / nrm

nvm

nvm is a version manager for node.js, designed to be installed per-user, and invoked per-shell. nvm works on any POSIX-compliant shell (sh, dash, ksh, zsh, bash), in particular on these platforms: unix, macOS, and windows WSL.[1]

nvm-windows A node.js version management utility for Windows. [2] This is not the same thing as nvm.The original nvm is a completely separate project for Mac/Linux only. This project uses an entirely different philosophy and is not just a clone of nvm.

nrm

nrm can help you easy and fast switch between different npm registries, now include: npm, cnpm, taobao, nj(nodejitsu).[3]


1.Node Version Manager 2.nrm -- NPM registry manager 3.nvm-windows

richardmyu commented 3 years ago

pnpm

Fast, disk space efficient package manager[1]

当使用 npm 安装依赖包时,所有软件包都将被提升到 node_modules 的 根目录下。其结果是,源码可以访问 本不属于当前项目的依赖包。pnpm 则是通过使用符号链接的方式仅将项目的直接依赖项添加到 node_modules 的根目录下[2]


1.pnpm 2pnpm

richardmyu commented 3 years ago

多句话总结

😓 😓 😓

npm 作为 node.js 的标准包管理器,应用较其他广泛;因为网络问题,国内用户并不能享受到 npm 的好处,转而借用 cnpm 来进行包的管理;另一方面,npm 实际使用时暴露了部分问题,yarn 应运而生,着重解决安装速度和安全问题。随着 yarn 发展壮大,npm 也跟着“进化”,改善了很多。

伴随着使用者增多和项目多,出现了 npm 自身版本管理问题,nvm (后面还有 nvm-windows)站了出来;而因为网络问题而诞生了不少的源,而 npm 源的切换也复杂多变了起来,于是就有了 nrm。

npm,乃至 yarn 都依旧有不能解决的问题:依赖存在多个版本而带来的冲突。对于树状依赖,目前有两种解决方案:1.扁平化;2.使用符号链接。npm 和 yarn 都使用了第一种方案,而 pnpm 则大胆的使用了第二方案。

以后会怎么样,接着看 😃