Angular library include external library

128 Views Asked by At

I am trying to include several dependencies in my library (ex. dashjs, leaflet, ...).

I know how to include it in a standard Angular project. Add dependencies to package.json and add each external library to the "script" tag in my angular.json file.

When creating an Angular library there is no angular.json file. Sadly the Angular documentation doesn't help either. Someone already figured out how to do it and can share details about it?

1

There are 1 best solutions below

1
ianianianian On

Your library has its own package.json, where you can specify its dependencies:

{
    "name": "myPackage",
    "version": "0.0.1",
    "description": "My Package.",
    "author": "Me",
    "dependencies": {
        "myDep": "1.1"
    },
    "peerDependencies": {
        "@angular/common": "^16.1.0",
        "@angular/compiler": "^16.1.0",
        "@angular/core": "^16.1.0",
        "@angular/router": "^16.1.0",
        "@angular/cdk": "^16.1.0",
        "@angular/platform-browser": "^16.1.0",
        "@angular/platform-browser-dynamic": "^16.1.0",
        "@angular/forms": "^16.1.0",
    }
}

Check out this tutorial: https://angular.io/guide/creating-libraries#peer-dependencies