安装节点软件包时,可以使用自定义目录名称代替“ node_modules”吗? [英] Can a custom directory name be used instead of 'node_modules' when installing node packages?

查看:104
本文介绍了安装节点软件包时,可以使用自定义目录名称代替“ node_modules”吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建一个 package.json ,运行 npm install ,它可以正常工作。它在我的根文件夹中创建一个 node_modules 目录(可以使用-prefix 选项更改该目录)。但是,我不太喜欢强调下划线。我想更改NPM将模块下载到的目录的名称。我希望它被命名为 nmods node-modules 或类似的名称。

I create a package.json, I run npm install, it works alright. It creates a node_modules directory in my root folder (which I can change by using --prefix option). However, I don't like underscores all that much. I want to change the name of the directory NPM downloads the modules to. I want it to be named nmods or node-modules or something like that.

Bower可以执行类似的操作,方法是读取其中的 .bowerrc 文件中的目录属性当前目录。

Bower can do a similar thing by reading the directory property inside a .bowerrc file in the current dir. Is there a way to do the same with NPM?

推荐答案

没有办法更改它。 node_modules 文件夹实际上不是NPM专用的,它是Node核心模块加载系统的一部分。 module.js

There is no way to change it. The node_modules folder is actually not specific to NPM, it is part of Node's core module loading system. Seen here in module.js.

如前所述,在全局范围内进行更改也可能会破坏您正在使用的某些模块,因为有时模块是打包的它们的依赖项已经存在于 node_modules 中,对其进行更改将导致该中断。

Changing it globally as you've mentioned would also potentially break some of the modules you are using too, as modules are sometimes packages with their dependencies already present in node_modules and changing it would cause that to break.

这篇关于安装节点软件包时,可以使用自定义目录名称代替“ node_modules”吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆