[英]Use a custom directory name instead of node_modules when installing with npm
I create a package.json
, I run npm install
, it works alright. 我创建了一个
package.json
,我运行npm install
,它工作正常。 It creates a node_modules
directory in my root folder (which I can change by using --prefix
option). 它在我的根文件夹中创建一个
node_modules
目录(我可以使用--prefix
选项更改)。 However, I don't like underscores all that much. 但是,我不喜欢那么多的下划线。 I want to change the name of the directory NPM downloads the modules to.
我想更改NPM将模块下载到的目录的名称。 I want it to be named
nmods
or node-modules
or something like that. 我希望它被命名为
nmods
或node-modules
或类似的东西。
Bower can do a similar thing by reading the directory
property inside a .bowerrc
file in the current dir. Bower可以通过读取当前目录中
.bowerrc
文件中的directory
属性来做类似的事情。 Is there a way to do the same with NPM? 有没有办法对NPM做同样的事情?
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. node_modules
文件夹实际上并不特定于NPM,它是Node的核心模块加载系统的一部分。 Seen here in module.js
. 在
module.js
看到这里 。
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
并且更改它会导致其中断。
Yarn you can easily achieve this by adding a file called '.yarnrc' with contents like this: 你可以通过添加一个名为'.yarnrc'的文件轻松实现这一点,其内容如下:
# ./.yarnrc
--modules-folder lib
Next time you run 'yarn' it will create the lib folder and install packages into there instead of into node_modules . 下次运行'yarn'时,它将创建lib文件夹并将包安装到那里而不是node_modules 。
Now if only we could get 'npm install' to be as clever. 现在,只要我们能够'npm install'变得聪明。
没有办法在npm中更改它,但是,有一个选项可以在yarn包管理器中配置它。
yarn install --modules-folder <path>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.