在package.json中指定node_modules的路径 [英] Specify path to node_modules in package.json
问题描述
是否有一种方法可以将应用程序中的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 env变量即可:
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屋!