简体   繁体   English

新建项目时是否应该安装所有 npm 包?

[英]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.

相关问题 当我尝试使用npm我安装我的项目包时出现错误 - I get an error when I try to install my project packages with npm i 我必须为每个新项目安装 npm 吗? - do I have to install npm for every new project? NPM:我应该使用依赖项之一的依赖项,还是应该在根级别将其明确安装到项目中? - NPM: should I use one of my dependencies' dependencies, or should I explicitly install it into the project at the root level? 为什么运行npm install时会得到很多软件包? - Why do I get a lot of packages when I run`npm install`? 无法在 Mac 上的 Visual Studio Code 中为项目安装 NPM 包 - Unable to install NPM packages for project in Visual Studio Code on Mac npm不安装下划线包 - npm not install underscore packages Npm安装对于所有软件包始终返回“代码ECONNREFUSED”错误 - Npm install always return `code ECONNREFUSED` error for all packages 我无法安装我的项目套件 - I am unable to install my project packages 我已经编写了自己的 npm 模块,当我将其导入新项目时,所有资产路径都相对于项目而不是模块内部? - I've written my own npm module, when I import it into a new project, all the asset paths are relative toward the project instead of inside the module? 尝试安装软件包时 NPM 缺少参数 #1 错误 - NPM missing argument #1 error when trying to install packages
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM