如何给 npm 包打补丁?

1 · Cell · Oct. 12, 2023, 3:42 p.m.
背景 今天鬼事神差想起去年写的一段 dirty hack 代码,当时是在 vue-minder-editor-extended 这个项目为了解决百度开源的 @7polo/kityminder-core npm 包的 bug,但是百度早在 17-18 年就停止更新了,我又不想自己 fork 一份源码然后重新发包,于是当时直接从 node_modules 里面复制出了打包后的源码进行修改,然后放到了项目中 src/script/patch/kityminder.core.js,并因修改了引入: 1 2 - require('@7polo/kityminder-core'); + require('./script/patch/kityminder.core'); 但是今天刷抖音看到类似的问题,回想起来这种做法真的是太蠢了,于是就想着有没有更好的办法,于是就一番搜索有了这篇文章。 安装 patch-package 1 npm i patch-package --save-dev 修改源码 在 node_modules 目录下找到需要打补丁的包,然后修改源码,比如我这...