使用patch-package更改node_modules的依赖包(简约版)

96 阅读1分钟

背景

patch-package是一个用来修复 node_modules 中 npm 包的工具。快速生成补丁文件,运行 npm install时,会自动更改补丁,避免了每次手动更改依赖代码的麻烦。

可以使用patch-package包修改node_modules文件

1.安装 patch-package

npm install patch-package

2.在 package.json 文件

image.png

在scripts 中加入"postinstall":"patch-package"

3.修改依赖包

在 node_modules 中找到需要修改的包,做出相应的改动。

4.执行命令创建

npx patch-package 你的包名字

此时在根目录下会得到如下文件

image.png