在 NPM/Node 中替换一个包 [英] Substitute a package in NPM/Node

查看:96
本文介绍了在 NPM/Node 中替换一个包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以强制外部 npm 依赖项使用提供相同 API 但不同实现的不同 node.js 包?

Is it possible to force an external npm dependency to use a different node.js package that offers the same API but a different implementation?

推荐答案

我建议下载你想要的 API 的代码,创建一个 src/assets 文件夹,把它放在那里,将 package.json 中的包名更改为某个东西未在 npm 中使用,然后在代码中使用 'require('newPackageName')'.

I recommend downloading the code for the API you want, creating an src/assets folder, placing it in there, changing the package name in package.json to something not used in npm, then using 'require('newPackageName')' within your code.

如果您决定使用 package.json 的某些功能来指向特定版本(例如使用1.4.7"而不是^1.4.7")或者如果您指向 github 地址,请注意你运行 npm update.它会将您的 URL 替换为 npmjs.org 中具有该特定名称的最新版本.我不知道在较新版本的 npm 中是否仍然这样做,但在适用于 Node.js 0.12 的版本中,这是默认行为.

If you decide to use some of package.json's capabilities to point towards a specific version (like using "1.4.7" as opposed to "^1.4.7") or if you point to a github address, be careful when you run npm update. It will replace your URL with the latest version in npmjs.org with that specific name. I don't know if it still does this in newer versions of npm, but in the version that works with Node.js 0.12, this is the default behavior.

我可以告诉你,节点收缩包装会起作用,但它也会阻止任何其他软件包的更新.不,你不能只有一个收缩包装的依赖,它必须是所有的,否则 npm update 将不起作用.

I can tell you that node shrinkwrap will work, but it will prevent any other packages from being updated as well. No, you cannot just have one shrinkwrapped dependency, it has to be all of them, or npm update won't work.

这篇关于在 NPM/Node 中替换一个包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆