Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does one go about creating an Angular library wrapper for an existing Javascript library?

Suppose there exists a Javascript library written in plain Javascript and commonly used on vanilla, non-frameworked websites. How does one go about creating an Angular library that can easily be npm installed that would make the library seamless to use in an Angular app?

I cannot find any good demonstrations of this process in the Angular docs or on the wider web.

Just for instance, there is a fantastic Javascript library called p5.js, which is not straightforward to use with Angular. How would one go about creating an Angular module that you can simply import into your own Angular module and use all of its great features with full Angular support?

like image 771
CodyBugstein Avatar asked Jul 16 '18 04:07

CodyBugstein


People also ask

Can I use JS library in Angular?

To use the JavaScript library in an Angular project, install the library via npm and check for its type declaration file. Install the type declaration file from @types/<library-name>, if it is not a part of the source code. import the library in your component and start using it.

Which command can be used to create a new library project in an Angular 6 workspace?

The Purpose of Angular Libraries To create a library, we generate it by “ng generate” command, built it by “ng build” command, publish by “npm publish” command. To use a library we install it by “ng i “ command.


1 Answers

Personally, I would go with Angular CLI. Angular CLI v6 has ng-packgr built in.

Take a look at the create library story. Its pretty straightforward and it will get you started quickly and guide you with the best practices for updates as well.

Update: For Angular CLI v7 and later, see documentation here

like image 176
Awad Maharoof Avatar answered Oct 01 '22 10:10

Awad Maharoof