[英]Should I install all the npm packages when making a new project?
A just started getting familiar with npm packages and node. A 刚开始熟悉 npm 封装和节点。 When installing packages they create a lot of folders in the "node modules" and i wonder if when i'll create a completely new project should i install all these packages again while having them already installed in previous projects?
安装包时,他们在“节点模块”中创建了很多文件夹,我想知道我什么时候会创建一个全新的项目,我是否应该再次安装所有这些包,同时已经在以前的项目中安装了它们? Or i just need to link the new projects with these packages with the package.json file?
或者我只需要将新项目与这些软件包与 package.json 文件链接起来?
You definitely shouldn't install all the packages - just those that you need.你绝对不应该安装所有的包——只安装你需要的包。
While there are some ways to save space in node_modules, but unless it's an exceptional situation, I wouldn't start with them.虽然有一些方法可以节省 node_modules 中的空间,但除非是特殊情况,否则我不会从它们开始。 It's much simpler to manage dependencies for every project independently, and it would save you a world of trouble if every project own its own dependencies and can upgrade/downgrade/replace them if needed.
独立管理每个项目的依赖项要简单得多,如果每个项目都拥有自己的依赖项并且可以根据需要升级/降级/替换它们,它将为您省去很多麻烦。
If you want to keep your project portable or make them usable for others, I you should just redownload the modules.如果您想保持项目的可移植性或使其可供他人使用,您应该重新下载模块。 If you link a folder on your PC and then send the code to someone else, they will not be able to execute it.
如果您链接 PC 上的文件夹,然后将代码发送给其他人,他们将无法执行它。 BTW if you want to publish your code on Github (or something similar) then you can add node_modules to.gitignore.
顺便说一句,如果你想在 Github(或类似的东西)上发布你的代码,那么你可以将 node_modules 添加到.gitignore。
It always depends on what you're wanting to build.它始终取决于您要构建的内容。 If you know exactly which packages you need to install, then you can install all of them beforehand.
如果您确切知道需要安装哪些软件包,则可以预先安装所有软件包。 But, most of the time, only "npm install" something when needed.
但是,大多数时候,只在需要时“npm install”一些东西。 Don't forget to add node_modules to.gitignore file too.
不要忘记将 node_modules 添加到 .gitignore 文件中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.