如何提升对全局模块的捆绑依赖关系?

发布于 2024-11-29 15:21:07 字数 513 浏览 1 评论 0原文

提升对全局模块的捆绑依赖关系的明显方法是将目录从 node_modules/foo/node_modules/baz 移动到 node_modules/baz 但这就是全部我要做什么?是否存在秘密握手,否则事情就会神秘地出错?

(当我问是/否问题时:我注意到 npm 将 node_module 放在我目前所在的任何目录下。这是预期的行为 - 我可以看到它对于依赖项的递归安装有何用处 - - 或者我没有讽刺地弄乱了 npm 的安装?)

(说到关于混乱安装的是/否问题,我的节点安装不会自动查看它自己的安装) > node_modules 目录,我有将其添加到 NODE_PATH 中。这是预期的行为吗?)

我使用 Node.js 两天后的评价:很棒的产品,我不明白为什么它没有比现在更受欢迎——我已经完全通过了解决一个在我习惯的标准 Apache/Tomcat 系统中绝对无法解决的问题——但是像上面这样的简单问题比大问题(“我如何连接到 MySQL”)更难找到答案。 ” “我该怎么办负载平衡?”)

The obvious way to promote a bundled dependency to a global module is by moving the directory from node_modules/foo/node_modules/baz to node_modules/baz but is that all I have to do? Is there a secret handshake, without which things will mysteriously go wrong?

(While I'm asking yes/no questions: I notice that npm drops the node_module under whatever directory I happen to be in at the moment. Is this intended behavior -- I can see how it would be useful for recursive installation of dependencies -- or did I, with no sense of irony, mess up the installation of npm?)

(And speaking of yes/no questions about messed-up installations, my install of node does not automatically look in its own node_modules directory, I had to add it to NODE_PATH. Is this expected behavior?)

My appraisal after two days of node.js: great product, I don't see why it isn't even more popular than it is -- I'm most the way through solving a problem that is absolutely unsolvable in the standard Apache/Tomcat systems I'm used to -- but it's harder to find answers to really simply question, like the above, than the big-picture ones ("how do I connect to MySQL?" "how do I load-balance?")

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

仅此而已 2024-12-06 15:21:07

npm 从 1.0 版本开始改变了它在全局和本地安装方面的方式。

简而言之,如果您想全局安装模块,可以使用 -g 标志。

npm install Awesome-module -g

如果你想在本地安装,你可以删除 -g 标志。

如果您希望您的模块仅在全局范围内安装,您可以添加

"preferGlobal": true

到您的 package.json

就您的第二个问题而言,是的,将 node_module 放入无论您位于哪个目录,它都是本地安装的一部分。

链接到 npm 1.0 发布博客: http ://blog.nodejs.org/2011/03/23/npm-1-0-global-vs-local-installation/

npm as of version 1.0 changed how it did it's installations in terms of Global vs Local.

The short answer is if you want to install a module globally you can use the -g flag.

npm install awesome-module -g

If you want it locally you drop the -g flag.

If you want your module to only be installed globally you can add

"preferGlobal": true

to your package.json

As far as your second question goes, yes it is the intended behavior to drop node_module in whatever directory you're in, that's part of the local installation.

Link to npm 1.0 release blog: http://blog.nodejs.org/2011/03/23/npm-1-0-global-vs-local-installation/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文