Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular module from Github, how to integrate in my module?

Summary

I'm looking for instructions on how to get a github-fork of a node_module integrated into my project, so I can use the module with my own modifications to it, without touching code inside node_modules/xyz.

Details / example / reason:

As an example I have found that angular/cdk drag and drop is quite nice, but has flaws. So I needed to change the code in node_modules/@angular/cdk/esm2015/drag-drop.js (which I don't want to).
But also plotly (https://github.com/plotly/angular-plotly.js).

Mostly, like with the cdk/drag-drop there's a github repository with source code. And of course, changing sth. inside node_modules is ultra stupid and obviously I'd prefer to fork the repository instead and then link my fork in the package.json or so (?!).

That said...
I don't know how right now.
I could not find any docs or blogs on this topic. I guess I must be choosing the wrong keywords ??!

What I'd like to ask for

Could someone please give a link to a page that explains this process in great detail or at least summarize the important steps ?

What's on my mind so far...
Where to put the repository relative to my project, can/must it be in a parallel folder ? In my main project how to link that new forked git module (is it in package.json ?) Do I need to separately precompile that forked git module after every change ? Which commands ? Or is there an option so that my main module/project compiles each change through the ng serve watch as well on development ?

like image 864
Allisone Avatar asked Nov 15 '25 14:11

Allisone


1 Answers

You have several options to use a dependency's fork in your Angular project:

If your fork is only available locally

Please check @Dino's answer.

Upload your fork on GitHub (or another Git host)

  • in your package.json, import the fork like that: "dependency": "git+https://github.com/your-username/your-git-repository.git"
  • your fork will be added to the node_modulesdirectory
  • be aware that you'll have to push all changes in your fork and execute npm i in your project again

To learn in detail how to import a GitHub repository as dependency, read also the official npm documentation.

Upload your fork on npm

  • sign up at npm to create an account
  • go to your fork directory: cd fork-directory
  • login to npm: npm login
  • initialize your package: npm init
    • check that your package name does not exist yet: https://www.npmjs.com/package/your-package-name should return a 404 error
  • publish your package: npm publish
  • in your package.json, import the fork: "your-package-name": "package-version" (package-version is the version number of your npm package)
  • be aware that each time you have changes in your fork, you'll have to publish a new package version with higher package version number than before and execute npm i in your project again

To learn how to publish an npm package, read also this blog post and the official npm documentation.

like image 93
Spark Fountain Avatar answered Nov 17 '25 09:11

Spark Fountain



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!