简体   繁体   English

如何在所有项目中使用一个node_modules

[英]How to use one node_modules for all projects

Is there an easy way to share one node_modules folders with all angular projects and thus avoiding to download same dependencies every-time when we create a new project ? 有没有一种简单的方法可以与所有有角项目共享一个node_modules文件夹,从而避免在创建新项目时每次都下载相同的依赖项? if yes , is the method recommended ( what are pros/cons) 如果是,是否建议使用此方法(优点/缺点)

Thanks for your time 谢谢你的时间

Package Managers namely npm and yarn have caching mechanism. 软件包管理器即npmyarn具有缓存机制。 The packages are download for the first time only and when you run the install command for the already downloaded package, they won't be downloaded again. 这些软件包仅是首次下载,并且当您为已下载的软件包运行install命令时,将不会再次下载它们。

That being said even if you don't have an internet connection you can still install previously cached packages. 话虽如此,即使您没有Internet连接,您仍然可以安装以前缓存的软件包。

Yarn is particularly awesome on handling this and npm is now catching up. Yarn在处理此问题方面特别npmnpm现在正在赶上。

This solves your problem of downloading the packages again. 这样可以解决您再次下载软件包的问题。 Do lock your package dependencies version. 请锁定您的程序包依赖版本。 This might help in using the same node_modules for other projects too. 这也可能有助于将相同的node_modules用于其他项目。 But I don't recommend using same node_modules folder for all projects personally as this might mess the entire project. 但是我不建议个人对所有项目使用相同的node_modules文件夹,因为这可能会使整个项目混乱。 Check out my article about dependency management in JS apps 查看有关JS应用程序中的依赖项管理的文章

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM