node.js 如何编辑通过 npm 安装的节点模块?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13300137/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to edit a node module installed via npm?
提问by user1810875
I'm using the node_swiz module, which in turn uses the validator module.
我正在使用 node_swiz 模块,该模块又使用验证器模块。
I want to make changes to the validator module, but I used npm install to install the modules/dependencies.
我想对验证器模块进行更改,但我使用 npm install 来安装模块/依赖项。
Can I just make changes to the validator module inside of node_modules, or will that node_modules dependencies be re-created and the latest version gotten when I publish to heroku or next time I run npm install?
我可以只对 node_modules 中的验证器模块进行更改,还是会重新创建 node_modules 依赖项并在我发布到 heroku 或下次运行 npm install 时获取最新版本?
The structure looks like this:
结构如下所示:
myNodeApplication
- node_modules
- swiz
- node_modules
- validator [this is the library I want to edit]
Thanks for the help!
谢谢您的帮助!
回答by Sdedelbrock
You can edit the file directly, but this would be overwritten whenever npm updates, the best thing to do is go straight to the source.
您可以直接编辑文件,但是每当 npm 更新时,这都会被覆盖,最好的做法是直接转到源。
If the changes affect functionality of the overall module, and may be useful to others, you may want to contribute to the original source on github and look for the change to be implemented.
如果更改会影响整个模块的功能,并且可能对其他人有用,您可能希望为 github 上的原始源做出贡献并寻找要实现的更改。
If this is proprietary functionality that is needed, and would not help the development of the module, the best thing to do is fork it from github and make your changes. You can install items directly from github using NPM, and this method would let you integrate future changes in to your custom version from the original source.
如果这是需要的专有功能,并且无助于模块的开发,最好的办法是从 github 中 fork 并进行更改。您可以使用 NPM 直接从 github 安装项目,这种方法可以让您将未来的更改从原始源集成到您的自定义版本中。
To install directly from github, use the following command:
要直接从 github 安装,请使用以下命令:
npm install https://github.com/<username>/<repository>/tarball/master
npm install https://github.com/<username>/<repository>/tarball/master

