This feels like a question a person shouldn't have to ask, but I've been searching for the past 3 hours how to do this and I can't figure it out.
Here is what I'm trying to do:
1) fork a library from a GitHub repo, let's call it vue-widget
2) I need to get the files on my local machine somehow, most documentation says to do git clone https://www.github.com/username/vue-widget.git
My problems immediately begin around here because I don't know how to load the library into my project. I am trying to do:
import Widget from '@username/vue-widget';
The part that is making me quite frustrated is that all the help documentation I can find is written as if I am doing a 1 character change and then submitting a pull request, but I am doing a potentially extensive modification, so I need to run the modified feature branch in my application. I can't find how to do that.
I found some documentation from NPM that indicates I might be able to use scoped packages, but I can't figure out if that's required. Do I really need to fork a project and then publish it under my own name on NPM? or is there a faster, easier way?
I also understand I may be able to include a hash in the import, like:
import Widget from '@username/vue-widget#ose847vg6seo5489ve4e45n';
I am super lost about how to import Widget
from a feature branch in my forked repo. I want to know what the most common and idiomatic way of doing this is.
My expectation is that there is a way I can clone my forked repo, create a feature branch, load that into my application, modify it, and then submit a pull request when it is ready.
[edit]: My problem was that the library I was forking had the
/dist
folder in the .gitignore file, so my installation was not able to initialize properly due to those files not being built.
The solution is to remove /dist
from the .gitignore file, then run:
npm run build
git add .
git commit -m "removed /dist from gitignore"
git push origin featureA
Then after that, back in the project you are trying to get the forked library into, do the solution that Max showed. In my case, I added this to my package.json
file and then ran npm install
:
"vue-widget": "username/vue-widget#featureA"
Here are some useful links that took me a while to uncover:
How to install a private NPM module without my own registry?
npm install private github repositories by dependency in package.json
https://docs.npmjs.com/files/package.json#git-urls-as-dependencies
This is the one that actually solved it for me:
npm install and build of forked github repo
Be sure to read the comments below as there are a couple nice URLs about npm link
that can be situationally useful.