[Feature] Create boilerplate for library
This is a feature request.
It will be great if we can create a basic boilerplate for creating libraries for pipes, components etc. This is the time when people may be willing to create components for angular 2 but due to the lack of this, it's tough. angular-cli already has a build system in place so it will be easier to integrate it here.
For example, If making a pipe, I won't need the whole src folder. A single file and a page where I can see the preview will do. This will make it easier for a lot of people.
We have this feature on the backlog, but it's probably only going to happen post v1 release.
Hi,
I've found a Yeoman biolerplate that might be used until this one is resolved: https://github.com/jvandemo/generator-angular2-library (Haven't tested it yet, but will, soon..)
Hope it will help, and take down the pressure from ng2-cli team ;)
Can't wait to use this in angular-cli :) @DxCx did you test this generator finally ? Because doesn't seems up to date with last angular version :/
@jaumard I tested it long time ago, yes i agree it's totally not up to date :\
Is there any resources about this for angular 2.0 ? I found for beta, alpha but nothing for the stable release...
i think now that the final is out, they might want to implement this soon.. @Brocco is there any near plans about this feature?
Would love to see this feature rather sooner than later. I understand that the wonderful heroes 👍 behind the cli have to manage their scope, but I am crossing my finger that it does not take too long.
It is becoming somewhat of a bottleneck w.r.t. reusability of developed code. An ETA, even it broad strokes, would be most appreciated.
@DxCx This is on the roadmap, but not in the immediate future.
It is sad to see that such an important feature is not being taken up as a priority. Angular2 is all about components but cli doesn't allow for making lib out of components, so that these can be reused across projects. Strange.
@vinaysoni I understand that this may be higher on your priority list, but there are more pressing issues for the team to focus on, such as build and test performance. Rest assured that this is something that will be supported by the CLI.
Hi @Brocco
Thanks for your reassurance on this. However, let me explain my perception of the situation and why I thought that this feature (support for library development) is a vital part that should not have been missing in angular-cli .
Let me begin by saying that my comment was not motivated because of my immediate personal need for building libraries.
I tend to think of cli as a tool similar to Maven Archetypes. A tool which can provide me scaffold of different kinds/pieces of applications - so that one can get started quickly - without having to do plumbing and with the best blueprints/practices. angular-cli, along the same lines, generates project, modules, components, pipes, enums etc.
In the Java world, we have had Maven Archetypes, to generate different kind of projects (java command line app, a Jar file, a J2EE app, a web app, a Spring Camel App - and the list is virtually endless). But the most important part of Maven Archetypes - which is the closest parallel to angular-cli is generation of libraries.
We live in the world of libraries. Maven generated Java jar, war, ear, zip files to NPM packages. In an enterprise environment, everything is broken down into libraries. Now, when I think about - did anyone spend time in performance testing the Archetype for J2EE app or it's Unit tests, the answer is No. I feel that it is a minute piece in a much larger effort. If your blueprints are correct, and you are generating the code according to the blueprints, why do you need to do performance tests? angular-cli is not a full blown code generation tool. It generates only a starting point in code - with the right plumbing/blueprints/best practices.
On the other hand, what angular-cli should have had from the day one, was the ability to generate a Library. Even before "ng new project" came into place, there should have been "ng new lib datepicker"
This is because, there won't be a single Angular 2 project, worth the salt, within the enterprise, in real world, that would be composed of one single monolithic application. Only amatures, or Angular2 students, or a small time web developer would build such a monolithic application (without breaking it down into components). They may do it as a proof of concept, and therefore could be the use case for "ng new project" and the rest of what angular-cli has to offer today.
For corroboration, you may look at Angular2 itself. It acknowledges the assertion I am making by providing modules and components. The idea, the spirit and the very purpose of Modules was that when a module is created, it should be packaged in its own library. This is what we have done for years in the java eco system on the Swing based UIs for many years. But where is the support to do this in angular-cli?
Also, Modules were introduced late. Angular-cli should have been nimble to include "Support for Libraries" as soon as Modules surfaced. The current variance between angular-2 and angular-cli doesn't reflect nicely on angular-cli. Without support for libraries, I can't see enterprise applications adopting angular-cli.
"Support for Libraries" would be the most important Use Case for angular-cli within an enterprise software development environment. This may be a bit hard for traditional Java Script developer to grasp. But with a first class Object Oriented programming language (Typescript) it won't be JS developers but C# and Java developers who would be building the next generation of reusable components and apps using Angular2. GUI applications, with Typescript and Ng2 will be larger than the JS apps of the past and will have much greater element of reuse.
In contrast, generating a route, or a component, or Enum are nice to have features but are relatively simpler and pale in front of the need for "Support for Libraries".
Thanks Vinay Soni
Hi,
i'm really appreciating the work on angular cli. i agree to what @vinaysoni wrote.
I want to get involved and make this feature come to life. Does somebody want to join and/or do a brainstorming session?
Here is temprorary workaround
I've managed to publish my project to npm. Here's what I did.
In angular-cli project my module went to single folder (component-warpper).
In that folder I've added index.ts with list of modules and components to export.
I also added package.json file.
Then in command line go to this folder and npm publish.
Now I can import it as node_modules in other projects.

I wholeheartedly agree. We've been using Angular-CLI to manage a component library since alpha 0.0.34 but the webpack upgrade killed it.
The crawl phase of this kind of support really just needs:
- to allow declarations to be emitted (maybe its possible now but with the first webpack release it threw all sorts of weird errors if you turned this on in tsconfig)
- the ability to generate barrels that make the API surface obvious.
- compile the barrels for distribution rather than build a single bundle.
We are still using Angular-CLI to build the demo app within our component library but have resorted to an NPM script like the following to build the library:
del-cli ./dist && tsc --outDir ./dist -p src/app && node-sass --include-path scss src/app -o ./dist && cp ./public/package.json ./dist && cp -R ./src/assets ./dist && cd src/app && find . -name '*.html' -exec cp --parents \\{\\} ../../dist \\; && cd ../.. && npm run inline-resources
which is clunky at best.
Material2 switching back to gulp should be a good indication that this support is needed.
I hope this feature will be implemented very soon because my temprorary solution has issue with code completion in IDE (PhpStorm in my case).
Thanks for all the work so far, I'm a huge fan of angular-cli!
This issue is idle for about 2 months now. Any plan on when this will be implemented? For the time being I will also try to come up with something on my own.
I have a live example, how to use angular cli for creating angular component library (with own dependencies, in that case @angular/material). It does not provides custom templates for code generation, but it's really no so many effort to setup a library (how often is it needed). It also will receive a benefits from angular-cli project:
- Default
angular-cliapplication, that could be used for documentation or sandbox experiments reasons. - Default test setup from
angular-clisupport - Easy migrations for a new version of cli by
ng initcommand. - I expect no effort to migrate to an official library template, when it will be present.
You could have a look into: app, lib, app-demo.
⚠️ For non angular-cli projects, those do not use typescript, you might need to configure additional typescript loader. For angular-cli project it works out from the box.
There are some things that will need tackled within the CLI project in order to support libraries (not just applications). The first issue will be to support multiple applications within a project, this will allow for multiple build paths not just a single application. Then in order to support libraries a separate , non-application, build process will need to be implemented as there are additional build concerns when building a library than when building an application.
This is a high priority item for the community and for the team and is most certainly on the roadmap, just not sure of the timeframe at this point. Thanks for your input and patience.
Thanks for the heads up Brocco. After building some simple mechanisms for my publishing process on my own I wondered if the angular-cli project would have really helped, because when publishing a library in certain cases you want to be very deterministic on what happens during the preparation and in the end be part of the package. I got a grasp on how much work this would be for the team to implement this in general in a smooth way.
Regarding libraries I assume this is one of the points where every CLI user has to think about the building process on their own if straightforward solutions like @nsmolenskii 's approach (thanks!) can't be used.
@nsmolenskii, hey, I've taken a look at your lib example. It seems to me that it's a simple angular module, without any build process on it's own. Is it correct, or am I missing something? We're looking into building a library using angular-cli without including angular sources into the build