在 package.json 中指定 node_modules 的路径 [英] Specify path to node_modules in package.json

查看:47
本文介绍了在 package.json 中指定 node_modules 的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在应用程序中移动 node_modules 目录,让我们说/vendor/node_modules 就像 bower 对 bowerrc 文件所做的那样?我认为它可以在 package.json 中指定,但我似乎找不到解决方案.非常感谢您的帮助.

Is there a way to move the node_modules directory in an application to let's say /vendor/node_modules like bower does with the bowerrc file? I thought it could be specified in package.json but I can't seem to find a solution. Your help is much appreciated.

推荐答案

是的,你可以,只需设置 NODE_PATH 环境变量:

yes you can, just set the NODE_PATH env variable :

export NODE_PATH='yourdir'/node_modules

根据文档:

如果 NODE_PATH 环境变量设置为冒号分隔的列表绝对路径,然后节点将在这些路径中搜索模块,如果它们在别处找不到.(注意:在 Windows 上,NODE_PATH 是用分号而不是冒号分隔.)

If the NODE_PATH environment variable is set to a colon-delimited list of absolute paths, then node will search those paths for modules if they are not found elsewhere. (Note: On Windows, NODE_PATH is delimited by semicolons instead of colons.)

此外,节点还会在以下位置进行搜索:

Additionally, node will search in the following locations:

1: $HOME/.node_modules

1: $HOME/.node_modules

2:$HOME/.node_libraries

2: $HOME/.node_libraries

3: $PREFIX/lib/node

3: $PREFIX/lib/node

其中 $HOME 是用户的家目录,$PREFIX 是节点的配置 node_prefix.

Where $HOME is the user's home directory, and $PREFIX is node's configured node_prefix.

这些主要是出于历史原因.强烈建议您将您的依赖项本地放在 node_modules 文件夹中. 它们将是加载速度更快、更可靠.

These are mostly for historic reasons. You are highly encouraged to place your dependencies locally in node_modules folders. They will be loaded faster, and more reliably.

来源

这篇关于在 package.json 中指定 node_modules 的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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