Reputation: 1
I have created a shared library and created new application feature library and I want to import shared library in the app feature library.
How can I import or include one library into another library?
Upvotes: 0
Views: 847
Reputation: 1884
The best way is to use your shared library as a node dependency in your application library.
Example: If you have created your shared library via npm command as follows:
ng generate library sharedlib
Then build your shared library and publish in any public (npmjs) or private (your organization specific like JFrog) artifactory with following command
npm publish sharedlib
And use it as dependency (add in package.json) in your application library as
"peerDependencies": {
"@angular/common": "^7.2.0",
"@angular/core": "^7.2.0",
"sharedlib": "1.0.0"
}
I believe importing shared library module (from public-api.ts file) in application library (if both in same repository) can also work, but that is not a best way to do it.
Upvotes: 3
Reputation:
You should add any library you use as peerDependencies in your library's package.json. Something like this:
"peerDependencies": {
"@angular/common": "^6.0.0-rc.0 || ^6.0.0",
"@angular/core": "^6.0.0-rc.0 || ^6.0.0",
"@angular/forms": "^6.0.0",
"@angular/material": "^6.4.7"
}
Assuming you've created the library using the cli with ng generate library my-library
, the peerDependencies node is already there.
This will avoid any conflict if the user of your library also uses the other ones too.
Upvotes: -1