简体   繁体   English

npm package.json全局安装?

[英]npm package.json install globally?

Is there any way to set an NPM dependency to be installed globally in the package.json file? 有没有办法设置NPM依赖项全局安装在package.json文件中?

Whenever I run npm update all the dependencies are installed locally. 每当我运行npm update所有依赖项都在本地安装。

Thanks. 谢谢。

我相信-g选项会导致全局安装。

Is your reason for installing globally in order to make new scripts available on the command line? 您是否在全局安装以便在命令行上使用新脚本? If so, I might have a workaround for you. 如果是这样,我可能会为您解决。

Just install your packages as usual (without the -g ): 只需像往常一样安装包(不带-g ):

npm install -S my_module_name

Including the -S flag or --save will help keep your package.json file up to date. 包括-S标志或--save将有助于使您的package.json文件保持最新。

As usual, your project's npm install step will install locally (as you have described). 像往常一样,您的项目的npm install步骤将在本地安装(如您所述)。 However, it will also produces a local folder containing symlinks to each of the project's npm-supplied command-line executables (located inside the node_modules/.bin/ folder). 但是,它还会生成一个本地文件夹,其中包含每个项目的npm提供的命令行可执行文件(位于node_modules/.bin/文件夹内)的符号链接。

Add that folder to your system path to enable command-line access to npm modules without requiring installation via -g , or root access to a machine: 将该文件夹添加到系统路径以启用对npm模块的命令行访问,而无需通过-g进行安装或对计算机进行root访问:

export PATH=/path/to/your/project/source/node_modules/.bin/:$PATH

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM