DEV Community


Edit npm package and persist the changes on npm install

Shivang Chauhan
Updated on ・1 min read

Have you ever wondered how you can edit any npm package and have those changes persist if npm i gets run?

You can use patch-package to do this, all you need to do is follow these steps -

  • Make changes to the npm package.
  • After making changes to the npm run this command npx patch-package (package name).
  • This command will create a patches folder inside your project directory and that directory will hold all the changes which you did to the npm package.
  • Now whenever you do npm i it will install the packages, to get those changes which you did in the npm package just run this command npx patch-package to apply the changes.

Now you are done, all your changes will be applied.

Making this process automatic

Just add the command as postinstall like this in package.json file -

"postinstall": "npx patch-package"

Discussion (0)

Forem Open with the Forem app