Reputation: 21380
I have an Angular library hosted in a git repository but not published to npm. The library is packaged with ng-packagr. Is it possible to import it as a git dependency in another project?
Simply specifying the git URL as a npm dependency does not work, because ng-packagr builds the Angular library into the dist
folder and that folder is usually published to npm. You can specify a postinstall
script, but how can you configure afterwards that the root folder of the library is actually in the dist
folder?
I don't want to publish to npm because the application is not open source. I could use a private npm repository, but I was thinking if I can avoid all the hassle.
Upvotes: 13
Views: 4140
Reputation: 9
Found a workaround. You can specify a git dependency in your package.json
file like so and then use a postinstall
script like this:
"scripts"
...
"postinstall": "npm i node_modules/some-package/dist/your-lib/your-lib-0.0.1.tgz"
},
"dependencies": {
"some-package": "github:github_username/some-package",
...
}
Upvotes: 0
Reputation: 1
Another option is keeping the contents of the dist folder in it's own repo. This is ONLY possible if you specify in the Library's package.json in ngPackage to NOT delete the destination path. You might also have to manually define the destination if you do this as well.
below is an example package.json
{
"name": "my-lib",
"version": "0.0.4",
"peerDependencies": {
"@angular/common": "^7.1.0",
"@angular/core": "^7.1.0"
},
"ngPackage": {
"dest": "../../dist/my-lib",
"deleteDestPath": false
}
}
you would then git init
inside of my-lib and push it to it's own repo. That repo would become the dependency to other projects.
Upvotes: 0
Reputation: 21380
What I did was actually to specify this as a git dependency, add a postinstall script and when importing I was importing library/dist
.
Upvotes: 2
Reputation: 41447
In the package.json
you can add git ssh as a dependency.
"dependencies": {
"some-package": "github:github_username/some-package"
}
Then you can import the package from the component.
Upvotes: 1