patch-package (opens new window)

  1. package.json 添加一下代码
 "scripts": {
+  "postinstall": "patch-package"
 }
  1. npm or yarn
npm i patch-package

or 

yarn add patch-package postinstall-postinstall
  1. 修改node_modules中的代码后运行
yarn patch-package package-name

or

npx patch-package package-name
  1. 会生成patches文件夹,包含 package-name+version.patch 文件

  2. 移除包,重新 yarn add package-name or npm i package-name会自动把补丁加进去