简体   繁体   English

使用npm进行安装时,请使用自定义目录名而不是node_modules

[英]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. 我希望它被命名为nmodsnode-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.

相关问题 npm不安装node_modules - npm not installing node_modules 如何在 docker 中使用 npm install? 在不安装 npm 的情况下安装 node_modules - How to use npm install with docker? Installing node_modules without installing npm npm安装时忽略node_modules中的自定义模块 - Ignore a custom module from node_modules when npm install NPM模块从/ Users / node_modules /而不是项目目录中获取 - NPM modules get required from /Users/node_modules/ instead of the project directory 为什么Express模块​​没有安装在其默认目录中,例如npm \\ node_modules? - Why the express module is not installing in its default directory e.g., npm\node_modules? “npm install” 在 node_modules 目录中安装所有依赖项,而不是将它们嵌套 - “npm install” installs all dependencies in node_modules directory, instead of having them nested npm不仅将模块安装到当前目录中,还将模块安装到node_modules中 - npm installs modules into current directory, not only node_modules 当npm在本地项目中安装GULP时-在node_modules中有很多文件夹-为什么? - When npm installing GULP in local project - I get a ton of folders in node_modules - why? 在本地安装软件包时,npm 是否会触及 node_modules 文件夹之外的任何内容? - Does npm touch anything besides the node_modules folder when installing a package locally? NPM是否在node_modules下安装非根依赖关系? - NPM Installing non root dependencies under node_modules?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM