a) Install library
- using yarn:
yarn add patch-package postinstall-postinstall --dev
- or using npm:
npm i patch-package --save-dev
b) In package.json add
"scripts": {
...
"postinstall": "patch-package"
}
c) Usage
First make changes to the files of a particular package in your node_modules folder, then run
yarn patch-package package-name
or
npx patch-package package-name
(where package-name matches the name of the package you made changes to for example react-native, react-native-push-notification etc...)
- Nested packages If you are trying to patch a package at, e.g. node_modules/package/node_modules/another-package you can just put a / between the package names:
npx patch-package package/another-package
It works with scoped packages too
npx patch-package @my/package/@my/other-package
d) Finally
A folder will be created in your project named as patches which will include all the library patches you made.
Then you can push the code to your git repository.
Whenever yarn install or npm install is run all the patches will stay.
Top comments (0)