简体   繁体   English

如何不使用 node_modules 文件夹?

[英]How to NOT use node_modules folder?

When I type npm install <PACKAGE NAME> , it saves the files in a folder called node_modules, and this makes the project very heavy (200-400 files).当我输入npm install <PACKAGE NAME> ,它会将文件保存在名为 node_modules 的文件夹中,这使得项目非常繁重(200-400 个文件)。

I wonder how the global packages works?我想知道全局包是如何工作的? I mean, the first thing that comes to mind is that when we install a package globally, is that the node.js will add the dependency on package.json and when the program runs, it goes to a folder on the computer where the packages are installed and goes use them.我的意思是,首先想到的是,当我们全局安装一个包时,node.js 会添加对 package.json 的依赖,当程序运行时,它会转到计算机上的一个文件夹安装并使用它们。

The way i'm doing, each project will have the entire library inside, almost as if I had cloned that library repository into my project.按照我的做法,每个项目都将包含整个库,就好像我已将该库存储库克隆到我的项目中一样。

Normally if you're using a version control system like git, you're supposed to have a .gitignore file where the node_modules will be ignored.通常,如果您使用像 git 这样的版本控制系统,您应该有一个 .gitignore 文件,其中 node_modules 将被忽略。

Meanwhile, if you're bothered about your local computer storage;同时,如果您对本地计算机存储感到困扰;

If your operating system is a Linux Distro try installing your packages globally so that all the modules will be stored in a single node_modules folder in the home directory.如果您的操作系统是 Linux 发行版,请尝试全局安装您的软件包,以便所有模块都存储在主目录中的单个 node_modules 文件夹中。 Do this using npm install -g package_name使用npm install -g package_name执行此操作

If you're using windows this will help如果您使用的是 Windows,这将有所帮助

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

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