angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

[Feature] Create boilerplate for library

Open ritz078 opened this issue 10 years ago • 73 comments

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.

ritz078 avatar Aug 14 '16 20:08 ritz078

@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" in package.json to new compiled output files.

nsmolenskii avatar Jan 19 '17 20:01 nsmolenskii

@nsmolenskii, got it, thanks for your reply

maxkoretskyi avatar Jan 20 '17 06:01 maxkoretskyi

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.

oliverjanik avatar Jan 27 '17 04:01 oliverjanik

+1 , x 1,000 if i could :-)

zpydee avatar Jan 30 '17 09:01 zpydee

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. :)

DxCx avatar Jan 30 '17 10:01 DxCx

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.

:)

johnpapa avatar Jan 31 '17 01:01 johnpapa

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.

DxCx avatar Jan 31 '17 08:01 DxCx

Hello @johnpapa, We like to make libraries too, do you have any pattern to show us.

cgnunezbantics avatar Feb 20 '17 18:02 cgnunezbantics

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.

filipesilva avatar Mar 09 '17 14:03 filipesilva

Thank you so much @filipesilva

BernhardRode avatar Mar 09 '17 14:03 BernhardRode

Does it make sense to try using this typerscript boilerplate : https://github.com/alexjoverm/typescript-library-starter ?

Toilal avatar Mar 15 '17 21:03 Toilal

That is nice, but the main problem from my experience is the AOT + Webpack bit.

oliverjanik avatar Mar 17 '17 00:03 oliverjanik

Do we have any timeline on when to expect 2.0?

nmorado avatar Mar 20 '17 20:03 nmorado

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.

danwulff avatar Apr 03 '17 23:04 danwulff

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.

playground avatar Apr 04 '17 12:04 playground

From my experience, you need to set up a bunch of tools on your own.

tl;dr:

  • ngc to ES5 target, generating *.js + *.d.ts + *.metadata.json, exclude *.ngfactory.ts from distributable package, optionally: include *.js.map in distributable package
  • inline templates and styles, compile pre-css languages to css, see angular/angular#15722
  • create am UMD bundle referenced in "main" property of package.json
  • create an ESM version (in ES2015 module format) referenced in "module" property of package.json
  • (possibly more...)

dherges avatar Apr 04 '17 13:04 dherges

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.

pedroapy avatar Apr 04 '17 14:04 pedroapy

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

ip7e avatar Apr 04 '17 14:04 ip7e

@Brocco you mentioned above there will be to support for multiple applications within a project. Is this available yet?

playground avatar Apr 04 '17 19:04 playground

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.

danwulff avatar Apr 05 '17 15:04 danwulff