简体   繁体   English

如何在项目中使用npm软件包的自定义版本?

[英]How can I use a custom version of a npm package in my project?

I use Primus in my project. 我在项目中使用Primus Primus is a wrapper for websockets libraries like sockjs, which I use. Primus是websockets库(如sockjs)的包装器,我使用它。

At server boot, primus creates a script, that will then be downloaded by our client, as the client part of the socket. 在服务器启动时,primus创建一个脚本,然后该脚本将由我们的客户端下载,作为套接字的客户端部分。 This script embeds the source code of sockjs. 该脚本嵌入了sockjs的源代码。 Problem, it uses the 1.1.2 version of sockjs, that contains a bug, fixed in version 1.1.4, but not in Primus yet. 问题是,它使用的是sockjs的1.1.2版本,其中包含一个错误,已在1.1.4版中修复,但尚未在Primus中修复。

I asked the maintainers of Primus to change it but the are too slow to do it. 我要求Primus的维护者更改它,但是这样做太慢了。 So I forked Primus , and I replaced the wrong file by the good one. 所以我分叉了Primus ,然后用好文件替换了错误的文件。

Now, I want to use this package instead of the wrong one, declared currently in my package.json. 现在,我要使用此包,而不是当前在package.json中声明的错误包。

I don't know what the good practice is in this case, the only solution I can think is to npm-publish my modified package under a different name, like amplement-primus, and then do npm install --save amplement-primus to insert it in my project. 我不知道这种情况下的良好做法是什么,我能想到的唯一解决方案是以其他名称(例如amplement-primus) npm发布修改后的软件包,然后执行npm install --save amplement-primus将其插入我的项目中。 I have no idea of it breaks a rule of npm. 我不知道它违反了npm的规则。

Do you think it's a good idea, or do you have something better in mind ? 您认为这是一个好主意,还是您有更好的想法? Thank you ! 谢谢 !

You can use forked repo to install the package. 您可以使用派生仓库来安装软件包。

like : 喜欢 :

npm install github_url_of_your_repo

For more details: 更多细节:

See this . 看到这个

I used the github url of the project to reference it in package.json: 我使用了项目的github url在package.json中引用了它:

  "dependencies": {
    "primus": "git+https://github.com/amplement/primus.git",
    "sockjs": "^0.3.19"
  },

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

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