1

I have created a custom library using the command inside my angular app

ng g library custom-lib

I was able to consume the library by building & packing and I was able to add the custom-lib in my original angular application.Next step i wanted to add the dependencies in my library.I wanted to add the bootstrap,jquery,fontawesome and others as dependency in my libraries's package.json

INSIDE LIBRARY PACKAGE.JSON

"dependencies": {
 "ng5-slider": "^1.1.14",
 "ngx-owl-carousel": "^2.0.7",
 "bootstrap": "^4.3.1",
 "core-js": "^2.5.4",
 "jquery": "^3.3.1",
 "popper.js": "^1.15.0",
 "font-awesome": "^4.7.0"
}

Now when the library is installed these dependencies also get installed in the node modules.Since there is no angular.json in library I am struggling to add the scripts and styles for the library.

My goal is to add the scripts and styles for my dependencies in my custom library so that when I install my library ,all my dependencies gets their styles and scripts loaded readily and I should not manually add them in angular.json.

Sathya Narayanan GVK
  • 849
  • 2
  • 16
  • 32

1 Answers1

1

as i have built an external angular CLI library for my application and i have the exact problem that you face it right now. i have searched for long time to understand is there any way to do that or no? something that is important is, when you want to use your library, you should have those dependency in your root App. and you can not move them to package.json file of external library. but when you want to use your library in another app, without those dependencies, it does not work. so it is my solution:

forget about adding dependencies in your library. just put them in your root of your application.

Seyed-Amir-Mehrizi
  • 720
  • 1
  • 5
  • 19
  • yeah..i understand many articles suggest to add in the main app.but I came across [https://stackoverflow.com/questions/54223504/angular-6-library-using-bootstrap] ..In this answer given by hiroko bretz seem to add the styles through library..And by any chance there is similar way to add the scripts also..Anyway thanks for your help. – Sathya Narayanan GVK Apr 10 '19 at 09:25