中枢代码,注目必读
// download:3w 52xueit com
vue 2.x 反馈式
Object.defineProperty
爱学it学无畸形
想到独一是从事先端建设的友友们详情都会碰到过删除node_modules依赖文献的情况,但你们有莫得发现删除的卓越慢,若是一些援用比拟多库的技俩,删除都得要一个小时,是以接下来我就从删除依赖为什么会慢和如何秒删除依赖两个方面去写这著作。
一、删除node_modules依赖文献为什么会慢?
径直通过图形用户界面删除 node_modules 文献夹慢,原因主要有以下5点原因:
(1)文献数目宽阔:node_modules依赖可能会有上万个文献和文献夹,那么就使得操作系统需要破耗卓越多的时刻来处理每一个文献的删除。
(2)文献系统缓存:操作系统有可能需要花时刻去刷新文献系统的缓存,卓越是关于那些当年拜谒的文献或目次。
(3)文献进度被占用:若是某些进度正在使用 node_modules 中的文献,也即是被正在援用,那么这些文献将无法被删除的,会弹出领导直到关连的进度开释。
(4)磁盘IO结果:硬盘或SSD的读写速率也可能成为瓶颈,尤其是在比拟老机械硬盘上,就地读写的性能较低就会卓越慢。
(5)图形界面结果:图形界面的文献经管器在处理无数文献时,可能会因为UI的更新和绘图而变慢。
二、如何快速完成node_modules依赖删除?
其实借助一个大呼行用具rimraf即可竣事秒删除,如下是具体的操作经过。
(1)先全局装配 rimraf
npm install -g rimraf
(2)实行大呼删除
rimraf node_modules
(3)从头下载依赖
npm install
详确1:或者若是你使用的是 npx(无需全局装配 rimraf)
npx rimraf node_modules
详确2:Vue技俩删除node_modules和改了设立要从头运转技俩,要否则会不奏效
三、rimraf为什么能快速删除node_modules?
rimraf其实是一个Node.js模块,它能提供一个跨平台的形状来删除文献和目次。它快速的主要原因其实主要有以下几点:
(1)异步操作:因为rimraf使用异步IO操作,那么它就不会禁锢事件轮回,能更高效地处理无数文献和目次的删除。
(2)递归删除:rimraf会递归地删除目次过头扫数子目次和文献,这比手动或使用某些操作系统大呼(如Windows下的rmdir)有更高的后果,因为后者有可能需要好屡次调用智力皆备清空一个非空目次。
(3)失实处理:rimraf大略更好地处理删除过程中可能出现的失实问题,比如权限问题或文献正在被援用的情况,它会尝试重试或跳过这些文献,而不是把通盘过程失败。
(4)跨平台兼容性:rimraf在不同的操作系统上的发达都是一致的,这就意味着在Windows、Linux也曾macOS上,它的性能和举止都是很接近的。
小结:
上头只是是博主日常用的处置智商j9九游会真人,但若是有更多有酷爱的智商或者那里写的不合便捷指正哈。