
Ruben's Blog | Ռուբենի Բլոգը
🔙 ..Importing local directory as a package in NPM🐁
Sometimes, we need to modify third-party libraries for our projects, but we don’t want to publish the changes as public packages. Both NPM and Yarn offer a simple solution to import a local directory as a package, allowing us to make modifications without the hassle of publishing.
Update: if your use case allows storing “diff files” you can use https://www.npmjs.com/package/patch-package, otherwise continue reading.
Let’s say we have package called foo-pack
Using NPM:
- pull the package to project root directory
- navigate to the directory
cd foo-pack
- install all dependencies
npm install
oryarn
- remove package.lock
rm package.lock
orrm yarn.lock
- modify package.json so it doesn’t contain link to the package
{
"name": "foo-pack",
"version": "3.76.0",
"description": "foo description",
"author": "foo",
// remove this part below from json 👇️
"repository": {
"type": "git",
"url": "https://github.com/foo-pack/foo-pack"
},
// remove this part above from json ☝️
"license": "Apache-2.0",
...
}
- run install again in order to generate correct lock files
npm install
oryarn
- go to your project directory
cd ..
- add foo-pack to your package
npm install --save ./foo-pack
oryarn add file:./foo-pack
- now if we go to our package json we can easily find
...
"dependencies": {
...
"foo-pack": "file:./foo-pack",
...
},
...
🎊 TADA 🎉
Benefits:
- Flexibility: Customize libraries for your project without restrictions.
- Real-time Updates: Changes are immediately reflected in your project.
- Isolation: Keep changes local, avoiding unintended bugs in other projects.
- Version Management: Easily switch back to the original version if needed.
Remember to document all the changes and/or use the mighty git. 🌳
Please give me feedback or make a comment on whatever help me improve. ❤️
Blog Menu
- 💼 hire my consultancy
- ℹ️ about me
- 📰 rss
- ⌛️ Spend a day with me
- tech and life
- 📝 blogs
- 2025-05-16
Spending 5 Minutes to Make a Point 📌
This blog post is an exercise. I want to make a point, and for that, I will need to do some research and tell a story. Telling a story Henry Ford was ...
- 2025-05-14
Non technical founders, Visionary Builders Community 👯♀️
This is my third community. I’m starting to understand how it works. People with similar interests or challenges tend to have similar insights a...
- 2025-05-13
2nd CTO Event Is Soon 🪞
What’s about it? I host Armenian CTO Community. We have already 109 members there. First event hosted 21 members! I am doing this for over 9 mo...
- 2025-05-12
Reducing the Friction to Post 🌪️
Eliminating the reasons I don’t blog, one by one. Opening the editor is a friction, writing is a friction, pushing is a friction, but I can make...
- 2025-05-07
Consistency and Time ⏲️
Do I have time to blog? Every time I wrote I will blog every day, I’ve reflected on this commitment in several posts: In I Need to Revisit My Bl...
- 2024-12-29
Then the Journey Is Not About Winning 🏆️
Winning is the target, but the journey is never about winning. You cannot be sure the path is correct. Even with guidance, there is a chance it’...
- 2024-12-28
Free Consultancy 💆🏻
Nobody buys it. When I provide it everyone is happy. Why? Maybe people don’t understand the offer, which is completely understandable. What I of...
- 2024-12-28
The Algorithm of the Dressings 🥬➕🥕➕❓️🟰🥗
Martun said he read many books about healthy food and didn’t become healthy. I agree, that reading and doing is very different. But I think that...
- 2024-12-25
Powered.community Meetup 🤝🏻
Well, it happened. The food was sushi, and people came with friends, some just checking in. I was so glad to see so many people I know and don’t...
- 2024-12-23
5 Books to Read Before 2025 to Transform Your Life 📚️
People are not computers, though we share traits such as short and long-term memory or processing power. You cannot install a “software” o...
- See all...
- 🔗 links