[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.
@maximusk yes, you are right. It is based on the distributing sources files(.ts, .html, .scss, etc) instead of compiled into .js + .d.ts. In case if you using any build system, that supports typescript loader (angular-cli as perfect example), this library will be loaded as normal module and will be bundled as part of your application based on your build configuration.
I assume, that as soon as angular-cli will support library mode, to migrate from current approach to a native one, it will require to:
- configure library mode (most probably some properties in
angular-cli.json) - change
"main": "lib/index.ts"and"typings": "lib/index.ts"inpackage.jsonto new compiled output files.
@nsmolenskii, got it, thanks for your reply
I just want to reiterate that this is vitally needed. There is no good way to package an AOT ready library for angular 2 right now. Everything out there is a collosal mess.
Don't let this turn into another router fiasco.
+1 , x 1,000 if i could :-)
if someone from angular-cli can have a chat with me explaining what needs to be done i don't mind taking this and opening a PR. :)
It is important to remember that this is an OSS project and if a feature we want isn't being worked on as fast as we desire, we can always donate our own time to help create PRs.
:)
exactly @johnpapa ;) i was creating libraries manually (mostly for myself and testing stuff), but Im not sure i was doing the right approach. that's why if i'm gonna open a PR i want to make sure it's being done properly.
Hello @johnpapa, We like to make libraries too, do you have any pattern to show us.
Heya, I just wanted to give a small update regarding this feature.
It's not going to be there for 1.0, but it's definitely going to be there for 2.0. So the only question is if it's gonna be there for 1.x - I cannot answer this yet.
It's one of those big features that requires a fair bit of design upfront so it's not something we're looking for people to help out in right now. But it is something we're paying a lot of attention to.
It is true that there isn't a lot of guidance on how to build a library right now. I'm working on a cookbook for angular.io about this topic and hope to have it out soon.
I'm basing the upcoming cookbook heavily on @thelgevold's excellent work on https://github.com/angular/angular.io/pull/2758, which was never merged. It is a good starting point currently, if you want to have a look.
Thank you so much @filipesilva
Does it make sense to try using this typerscript boilerplate : https://github.com/alexjoverm/typescript-library-starter ?
That is nice, but the main problem from my experience is the AOT + Webpack bit.
Do we have any timeline on when to expect 2.0?
Hey @filipesilva I am just starting to look at creating a component library for some upcoming Angular apps and was wondering how the cookbook might be coming along? If I told you that I could hold off on starting a component library for a week or two, would you be gracious enough to give me a recommendation whether to try tackling this now or later? I'm also somewhat new to the Angular (2+) world, if that knowledge is of much worth.
I also saw that you've been active recently in this: https://github.com/filipesilva/angular-quickstart-lib Is this usable atm? Or would you recommend first looking at thelgevolds work before that? angular/angular.io#2758 Let me know if I can help guinea pig anything related to library development.
100% agree with @vinaysoni expressing the need of being able to create reusable/distributable libs with ng cli. @danwulff @filipesilva I'm also looking to start a project soon within a couple of weeks that will require the ability to create such shareable/distributable libs. Any recommendation between now and then will be appreciated. I'm vigorously search for solutions and alternatives, but I hope ng cli will be able to provide that.
From my experience, you need to set up a bunch of tools on your own.
tl;dr:
ngcto ES5 target, generating*.js+*.d.ts+*.metadata.json, exclude*.ngfactory.tsfrom distributable package, optionally: include*.js.mapin distributable package- inline templates and styles, compile pre-css languages to css, see angular/angular#15722
- create am UMD bundle referenced in
"main"property ofpackage.json - create an ESM version (in ES2015 module format) referenced in
"module"property ofpackage.json - (possibly more...)
We have made a library of components with gulp and webpack. The important part as mentioned @dherges is to generate the *.d.ts and *.metadata.json.
If it helps someone, this is our library: https://github.com/stratio/egeo , the important part are the files:
- gulpfile.js
- tsconfig.gulp.json
- config/webpack-components.js
- tsconfig.lib.json
So far this is working for us. We are waiting for a "official/angular-cli" way to do a library.
I suggest to check repo of material2 and spend some time how it's done
They're using gulp and systemjs for dev sanbox app, but you can use final library whenever you want. It also provides UMD bundle.
So, just a tip: spend some time and if you will reformat/reorganize everything depended your needs, you will come up with the most flexible solution
@Brocco you mentioned above there will be to support for multiple applications within a project. Is this available yet?
Thanks folks for the recommendations, I appreciate it a lot. I'm putting this off for a few weeks but I'll let you know how it goes when I get around to it.