NPM package with dependencies for global installation only?

If an NPM package is designed both as a global command and as a dependency for other applications / packages, may I specify its dependencies for different installation cases?

E.g., package mypkg depends on package foo when it runs as a global command. However, foo is unnecessary when mypkg is installed and used as a dependency for other applications / packages. How to prevent foo installed when -g | --global option is absent?

[zh-CN] 例如,mypkg 作为全局命令运行时,需要依赖 foo;但如果它仅作为其他应用程序或包的依赖项,则并不依赖 foo。怎样可以在非全局安装模式下,阻止安装 foo

In another word, I mean
[zh-CN] 换句话说,我的意思是

# Please DO NOT install **foo**.
npm install mypkg

# Please DO install **foo**.
npm install --global mypkg


Read more here: https://stackoverflow.com/questions/66271670/npm-package-with-dependencies-for-global-installation-only

Content Attribution

This content was originally published by Youngoat at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: