
如何优雅的更改node_modules的源码
配置步骤:
- 安装
patch-package和postinstall-postinstall:
你需要确保已经安装了
patch-package和postinstall-postinstall,以处理在安装依赖时自动应用补丁的工作。yarn add patch-package postinstall-postinstall或者使用 npm:
npm install patch-package postinstall-postinstall修改
node_modules中的文件:
直接在node_modules中找到你需要修改的包并进行修改。生成补丁:
在修改完成后,运行以下命令来生成补丁文件:npx patch-package [package-name]例如,如果你修改了
react-native-daterange-picker,命令应该是:npx patch-package react-native-daterange-picker这会在你的项目根目录中创建一个
patches文件夹,里面存放了补丁文件。在
package.json中添加postinstall脚本:
为了确保在每次执行yarn或npm install后自动应用补丁,你需要在package.json中添加一个postinstall脚本:"scripts": { "postinstall": "patch-package" }
如果你的项目已经有一个 postinstall 脚本,确保将 patch-package 添加到其中。
这样之后每次重新安装依赖会自动添加补丁 非常优雅~😛
如何优雅的更改node_modules的源码
评论



.webp)



.webp)
.webp)