angular / angular-cli

CLI tool for Angular
https://cli.angular.io
MIT License
26.74k stars 11.98k forks source link

[Feature] Create boilerplate for library #1692

Closed ritz078 closed 6 years ago

ritz078 commented 8 years ago

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.

nsmolenskii commented 7 years ago

@filipesilva, thanks for a really reasonable comment.

I'm not pretend, that my suggestion is a proper way to manage components libraries, it is just workaround until official support by angular-cli finished. I have to admit, that such suggestions would never have appeared, if this issue had been solved.

Now you feel the irony of the situation, don't you?

achieverprince commented 7 years ago

@filipesilva

Thanks for the update. I will check https://github.com/filipesilva/angular-quickstart-lib I know you guys will have lots of other issues to focus on. Hoping to see an update from cli team soon :)

@nsmolenskii Finally every thing works here , used this npm plugin for svn support in repository. At least i was happy that we are able to bring a temp solution to the desk to keep the project going.

dherges commented 7 years ago

Hi, for my purposes, I scrambled together a packaging script that does all the necessary transformations and produces a library in the Angular Package Format:

https://github.com/dherges/ng-packagr

There are still issues, minification is not yet implemented , source maps need to be re-mapped, and the source maps from downleveling with tsc are lost ... so I will neither support this nor publish this to npm. Things are inspired by the build tasks from the material2 team

If you like, let's try to incorporate this into Angular CLI. Is there anyone working on the compile library feature? If yes, who can I get in touch with?

Cheers! :beers:

UPDATE: I even added the source-map transformation chain.

filipesilva commented 7 years ago

@dherges I appreciate your offer but we're not yet open to contributions for this new feature :/

dherges commented 7 years ago

@filipesilva Ok, no deal.

Given that, I am looking for people from the community who are interested in implementing a packaging tool for Angular libraries. You can contact me here on my Twitter account

dherges commented 7 years ago

In contradiction to what I just said a very very loooong time ago, I decided to publish ng-packagr.

Once again, I stress that I am not really able to support this tool for everyone. I believe that a community effort will lead to way better results than one individual can ever achieve. Feel free to use ng-packagr when it suits your needs! If you find any issues or want to add missing features, don't hesitate to contact me ... open issues or pull requests! It's always welcome!

rjcorwin commented 7 years ago

It looks like our company is going to hold back on publishing our Angular modules to the Open Source community until this is figured out. We need to spend more time writing application code, less time maintaining our own custom build chain. We're happy to contribute some hours to helping standardize on this.

oliverjanik commented 7 years ago

Thanks to everyone who threw starter packs together. We've struggled with this problem too and spent countless hours on our NG2 builds. In the end some combination of ngc, webpack and custom gulp tasks worked for us.

To angular team: Angular is loosing ground to React and Vue and others for developer mindshare. Mainly due to the fact that it's so damn hard to package reusable components. This should be your number 1 concern to kick start Angular community.

achieverprince commented 7 years ago

@oliverjanik
I absolutely agree with you. Angular should support code sharing(library) as soon as possible

benetis-bentley commented 7 years ago

@achieverprince that is disrespectful to framework authors. IMHO framework can be anything for anyone. And remember, we get it for free (which is kinda amazing) - if you don't like something - patches are always welcome

orizens commented 7 years ago

I used https://github.com/robisim74/angular-library-starter with 3 npm packages (http://npmjs.com/~orizens) thus far and it's working quite well with AOT

litzebauer commented 7 years ago

Check out https://github.com/gonzofish/angular-library-set

achieverprince commented 7 years ago

@benetis-bentley Not at all, i am not disrespecting any framework or anyone. We all are here because of the wonderful framework Angular and i love to use it. I was just worried, Angular should not lose its popularity because of this.

My words would have been little harsh, i apologize if i have hurt any one. (edited my previous comment as well)

I do have to say, it is getting harder than angularjs because of the fragmentation... (angular 2, angular 4), even upgrading the framework from angular 4.0.3 > 4.1.2 broke the build (I think it has nothing to do with the framework, it is problem with the CLI) It is going out of scope for this issue, so i ll leave it here.

I am just a encouraged developer looking to promote Angular.

pjpenast commented 7 years ago

@achieverprince

Unfortunately I agree with you. The Angular team has not been able to create a simple framework for the community. Instead he has put more inconveniences along the way than improvements.

In my team we have made a library for Angular 2/4 and we have had many problems to support the different versions and, above all, the AOT compilation.

If a framework wants to be successful it needs the community, and it is evident that Angular 2/4 has not been built with the community in mind.

It would be well if the Angular team would participate in the reflection created in this issue and tell us their impressions.

rjcorwin commented 7 years ago

Perhaps the idea of what an Angular Library needs to change to better go with the flow that Angular CLI supports. My thought is that instead of attempting to create an alternative set of build tools for Angular Libraries (ex. https://github.com/gonzofish/angular-library-set), libraries could be included directly into an Angular CLI based project in the /src/app/contrib/<angular library module name> directory so that the standard Angular CLI build chain picks it up. This might get messy with dependency management but Open Source projects like Drupal were able to foster a thriving ecosystem of community contributed modules that did not have the luxury of being able to use their own specific version of some dependency.

gonzofish commented 7 years ago

@rjsteinert I agree that creating third-party tools don't solve the problem--I created Angular Librarian when I realized using the CLI wasn't going to be possible/too cumbersome to create a library.

I'd love to incorporate what librarian and other generators have done into the CLI to perpetuate a set of standards & practices when it comes to developing Angular code.

DmitryEfimenko commented 7 years ago

It's great to see so many people eager to help with this feature, however @filipesilva commented above:

I appreciate your offer but we're not yet open to contributions for this new feature :/

I think this means that Angular team is working hard on this feature. I only hope to see an update with the progress/roadmap to calm the community down a bit.

playground commented 7 years ago

@DmitryEfimenko I think that would be great for the community to get an update with the progress as many of us in the community have been eagerly waiting for this feature to be out.

achieverprince commented 7 years ago

@DmitryEfimenko I doubt that, cos the priority is still "required". I think the Angular team has other major issues to deal with in their bucket.

I absolutely respect the team on prioritizing the issues (they know the actual situation) I think we shouldn't pressure them as well, but what other choice do we got.

hansl commented 7 years ago

Thanks everyone for your comments.

We really appreciate the discussion regarding libraries, but unfortunately this will not be implemented as part of CLI 1.x. There are multiple challenges that are insurmountable with library support and the current state of the CLI. Here are a few examples (in no particular order, and non-exhaustive):

  1. Webpack does not support the kind of modules we're looking for when publishing Angular libraries (e.g. metadata.json and d.ts files).
  2. Webpack does not support (but it's on the roadmap) outputting ES6 code like we suggest for flat modules.
  3. We do not have a story yet for a real multi-application projects, which is required for developing libraries (you want a demo app, a development app and an e2e app for developing libraries).
  4. We do not have support for custom templates, and creating templates right now is particularly expensive for us.
  5. We do not have support for having multiple entry points.
  6. There's no proper serve/test/e2e, or even build stories for libraries in particular. What I mean by this is that no design has been done yet on how e.g. ng serve in a library would even work. This is a surprisingly hard problem for us because the CLI should stay as simple-to-use as possible. Same goes for ng test; our current karma config relies heavily on Webpack (see points above).

There are of course other problems that arise when building a CLI tool that supports both libraries and applications while being simple and straightforward to understand.

As for the way forward, we are currently building our Angular Development Kit and in the early design stages. We are rethinking the build story entirely and taking into account libraries from the start. Unfortunately the timeline for the DevKit is rather fuzzy, but once we have something more concrete we will share it with the community.

I'm going to lock this conversation for now, to make sure people coming into this thread see this message. I am not entirely sure this issue will live on as we move to the DevKit, but wherever news happen on library support in the CLI I will point to from this thread so people can follow.

Thanks everyone.

hansl commented 7 years ago

Addendum: We are in the process of adding custom template support to the CLI, and with it another tool that can be used to generate just templates but outside the CLI. We will consider having a scaffold for basic library projects, but it will not be part of the Angular CLI.

hansl commented 7 years ago

I created https://github.com/angular/angular-cli/issues/6510 to keep this thread locked, but the conversation going. Please continue the discussion over to the new issue, so that people coming here see the official answer.

filipesilva commented 6 years ago

In version 6.0.0 of Angular CLI you will be able to create, test and lint libraries.

This functionality is available in the latest RCs of 6.0.0, and documentation can temporarily be found at https://github.com/angular/angular-cli/blob/master/docs/documentation/stories/create-library.md. Once 6.0.0 reaches final, the documentation will be moved to the main wiki.