Press "Enter" to skip to content

How to npm install react component from forked github repository?

vpandzic 0

How many times you spotted some bug in npm library and just wanted to make small change (or large one) or you wanted some piece of functionality that was missing in original library but you still want simplicity of npm install whatever.

Well, you can npm install directly from github repository. All you have to do is:

npm install githubusername/libraryname

For example:

npm install vladop/react-particles-js

You will probably want to install with --save or --save-dev dependency like so:

npm install vladop/react-particles-js --save to save it as dependency in your package.json.

This ofcourse is not something specific only for projects related to React. Every npm package can be forked and installed from github.

For newbies I will explain whole process:

To fork github repo you can edit file and save. Forked version will be created on your account as it was your own repository.

forking-github-repo How to npm install react component from forked github repository?

For example I want to make edit of  React-particles-js project because it didn’t render children components so I edited content of Particles.tsx file inside src folder and changed it’s render method like so:

edit-file How to npm install react component from forked github repository?

I then run npm install vladop/react-particles-js, webpacked my code and I saw no change. This is because main script specified in package.json (using main property was set to "main": "lib/particles.js",.

particles.js is created by webpacking so this is what I did:

Cloned repository on my local harddrive:

1.) Create folder on your computer

2.) In command prompt go inside that folder and type git init, git remote add origin "github url of project for example https://github.com/vladop/react-particles-js.git", and git pull

3.) You can then install packages because node_modules is never commited to github (use npm install)

What I noticed is that in my case dev dependencies were not installed so I typed this command npm install --only=dev and then I run webpack to generate particles.js file.

Then commit file to github using git commit -m "webpacked", git push

Particles.js is webpacked and on  github servers so when I do again

npm install vladop/react-particles-js

and webpack my code I can see changes. Great thing about being able to install from forked github repo is the fact that is fast to make changes and install package, and also when you want to install original package (when your pull request is accepted) you can always type again npm install name-of-original-packahe-in-this-case-react-particles.js without any further change or step to take.

    Leave a Reply

    Your email address will not be published. Required fields are marked *