Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using angular-cli to build a library other projects can install

Here is a little background:

I created an angular-cli (beta 17) project for my organization that contains several components I'd like to share with other Angular 2 projects in the organization.

I started out keeping it simple, just using npm to install the GitHub repo into an implementation app and importing the components. I thought this was going to work as it compiled just fine, but running the app in the browser produced a 404 error when the template HTML file for the imported component could not be found.

I even tried using inline HTML templates within the component's definition, but it was still trying to find the HTML file.

Is there a good way to use angular-cli to build a component library app in a way that would allow other projects to install and use it? If not, what would be a good alternative? Thank you for any assistance.

like image 290
Chris Collins Avatar asked Oct 24 '16 14:10

Chris Collins


People also ask

What Angular CLI command can be used to create a library?

The ng generate command creates the projects/my-lib folder in your workspace, which contains a component and a service inside an NgModule.


1 Answers

This is currently not supported by the Angular CLI, but it is on the roadmap to be supported in the future.

The current process I've seen followed for libraries is a custom build process. I would suggest finding a library that you've used via npm, track it back to github, where it is likely maintained, and politely borrow their project structure. The main feature right now to ensure it supports is AoT compilation, your users will thank you.

like image 159
Brocco Avatar answered Nov 10 '22 16:11

Brocco