You need to try this NPM Package

You need to try this NPM Package


2 min read

The title might sound clickbait but I really find this NPM Package to be extremely useful. The Package I'm talking about is patch-package.

Last week I've made an app, Postzy, and I needed a clean way to slightly modify one NPM Package I was using. This is when I come across patch-package. I was so happy because it was doing exactly what I needed it to do (and this rearely happens with a package ๐Ÿ˜ƒ).

How does it work?

It's very simple to use.

Patch a package

You first need to go and make some changes to a package inside your node_modules folder.

After that, you can run npx patch-package [package-name] or yarn, if you're using yarn.

It will create a folder called "patches" inside the root folder of your project. You'll need to commit this folder to git to share the patch with your team and also deploy the changes to your server (depending on your deploy flow).

Apply a patch

After you made a patch, to apply it you can define a npm run command like "postinstall": "patch-package". You can run this command on the server after npm install or on your local machine to apply the patch.

If you have any question, don't hesitate to contact me.