Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

`npm install` from sub directory of a Git repository

Greeting, I have created an angular library and I have built & pushed it into private repo in gitlab, now I need to consume it inside another project

so I have tried to import it using the following line in package.json

"my-core-lib": "git+ssh://[email protected]:<username>/my-core-lib.git"

But that was downloaded the whole repo and put it inside node_modules including "dist" folder

I need to import the content of "dist" folder and not the whole repo something like:

"my-core-lib": "git+ssh://[email protected]:<username>/my-core-lib.git/dist"

Thanks in advance

like image 582
Jovani Avatar asked Apr 08 '19 15:04

Jovani


People also ask

Can npm install from GitHub?

The npm installation from GitHub is quite useful for testing packages. It also gives the flexibility to install any specific branch, version, tag, and so on.

How do I download a specific directory from a git repository?

GitHub User Interface There's a download button on the repository's homepage. Of course, this downloads the entire repo, after which you would need to unzip the download and then manually drag out the specific folder you need.

How do I add a git repo to a npm package?

To npm install a public project that is hosted on Github, and not the NPM registry, add the Github repo to package. json dependencies using the username/repo#branch-name format. Run npm install and npm will download the project and save it into your /node_modules/ folder.

Does npm install sub dependencies?

By default, npm install will install all modules listed as dependencies in package. json .


1 Answers

If the package source is hosted on GitHub, you can use GitPkg like this:

# using npm:
npm install https://gitpkg.now.sh/<user>/<project>/<subdir>?<commit-ish>
# using yarn:
yarn add https://gitpkg.now.sh/<user>/<project>/<subdir>?<commit-ish>

There is a nice wizard-like form at their site that helps build the URL, and the command to install it.

like image 75
Shayan Toqraee Avatar answered Sep 16 '22 16:09

Shayan Toqraee