背景

需要对第三方npm依赖包进行定制化修改

准备

  • 安装: npm i patch-package
  • 修改package.json
    // this will auto excute npx patch-package after npm install
    "scripts": {
        "postinstall": "npx patch-package"
    }
    

使用

  1. make changes to the files of a particular package in your node_modules folder
  2. npx patch-package ${package-name},例如:npx patch-package @aws-sdk/lib-storage
  3. if you want to apply patches, run npx patch-package

Benefits of patching over forking

  • Sometimes forks need extra build steps, e.g. with react-native for Android. Forget that noise.
  • Get told in big red letters when the dependency changed and you need to check that your fix is still valid.
  • Keep your patches colocated with the code that depends on them.
  • Patches can be reviewed as part of your normal review process, forks probably can’t

参考