当全局可用时,不要通过 npm install 安装本地模块
Do not install local modules via npm install when global available
如何配置package.json使得全局可用的依赖项不会在本地再次安装?
例如,我有一个项目,jshint 被列为开发依赖项;但是,我已经全局安装了 jshint,我希望这个模块使用全局 jshint。
不确定您要做什么,但无论如何在代码中使用全局依赖项都不是首选方式。
要获取一些信息,请键入 npm help folders
,这是 tl;dr 部分:
- Local install (default): puts stuff in ./node_modules of the current package root.
- Global install (with -g): puts stuff in /usr/local or wherever node is installed.
- Install it locally if you're going to require() it.
- Install it globally if you're going to run it on the command line.
- If you need both, then install it in both places, or use npm link.
因此,在您的情况下,最后一项 link
是答案:https://docs.npmjs.com/cli/link。
您需要 运行 npm link jshint
在您的基本文件夹中。它会 link node_modules/jshint 到全局。这将为二进制文件创建一个符号 link,但是,您不能在代码的某些位置在 require()
中使用它。如上所述,全局包在命令行上 运行 所以它们是二进制文件。
毕竟我最终使用 npx
来处理需要全局安装的东西,例如,在 npm 脚本中使用 npx standard
。无论全球存在如何工作。
如何配置package.json使得全局可用的依赖项不会在本地再次安装?
例如,我有一个项目,jshint 被列为开发依赖项;但是,我已经全局安装了 jshint,我希望这个模块使用全局 jshint。
不确定您要做什么,但无论如何在代码中使用全局依赖项都不是首选方式。
要获取一些信息,请键入 npm help folders
,这是 tl;dr 部分:
- Local install (default): puts stuff in ./node_modules of the current package root.
- Global install (with -g): puts stuff in /usr/local or wherever node is installed.
- Install it locally if you're going to require() it.
- Install it globally if you're going to run it on the command line.
- If you need both, then install it in both places, or use npm link.
因此,在您的情况下,最后一项 link
是答案:https://docs.npmjs.com/cli/link。
您需要 运行 npm link jshint
在您的基本文件夹中。它会 link node_modules/jshint 到全局。这将为二进制文件创建一个符号 link,但是,您不能在代码的某些位置在 require()
中使用它。如上所述,全局包在命令行上 运行 所以它们是二进制文件。
毕竟我最终使用 npx
来处理需要全局安装的东西,例如,在 npm 脚本中使用 npx standard
。无论全球存在如何工作。