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

[RFC] Library Support and Boilerplate Comment Thread

Open hansl opened this issue 9 years ago • 163 comments

As a follow up for https://github.com/angular/angular-cli/issues/1692#issuecomment-304970595.

Continue the conversion here.

hansl avatar May 30 '17 18:05 hansl

@Holzberg can you be more specific with what you mean by "errors out"? (Maybe better to open an issue there for this conversation :))

deebloo avatar Jan 26 '18 05:01 deebloo

@alexeagle do you know if video recorded of event: https://www.meetup.com/it-IT/Angular-MTV/events/246637957/ will be published quite soon?

meriturva avatar Jan 29 '18 15:01 meriturva

@meriturva The video is up here: https://youtu.be/QfvwQEJVOig?t=1h12s

juristr avatar Feb 11 '18 15:02 juristr

Waiting for an "official" process also. Submoduling an angular project through git submodule works in the mean time..

LuckyMallari avatar Mar 05 '18 06:03 LuckyMallari

There's a WIP currently that may allow to include ng-packagr (https://github.com/angular/devkit/pull/444) as a build tool into the Angular CLI in the future, among other possibilities.

Meanwhile using ng-packagr is perfectly fine, or you can use a more "monorepo" setup which is promoted by the nrwl/nx Angular CLI extension. I've talked about these recently, video of the talk should be up very soon as well:

  • Repo: https://t.co/ot047dqi8J
  • Slides: https://t.co/grXGmuQ5bN
  • @eggheadio video: https://t.co/e9dogjKKlg

The repository in specific has branches which show the various setup possibilities.

juristr avatar Mar 05 '18 12:03 juristr

@juristr please post the video here when uploaded, very very needed, thanks :)

avatsaev avatar Mar 05 '18 16:03 avatsaev

So for everyone interested, my talk from ngVikings is up:

  • Video: https://www.youtube.com/watch?v=Tw8TCgeqotg
  • Slides: https://goo.gl/GMnJv3
  • Repository: https://github.com/juristr/ngx-tabs-libdemo

juristr avatar Mar 11 '18 11:03 juristr

I also would like to share something I came up with in order to make kinda final solution for the overall problem. Maybe it sounds a bit trivial, but still it could be helpful for somebody.

The repo of @juristr is able to create a library but there is also a requirement to have a demo for the library, right? So, the idea is that the repo has / uses:

  • all angular/cli features
  • ng-packagr in order to build the library

We can extend it with the idea that the angular cli app is a demo app where one can develop and see the result while developing and, most important, show the library in action to the consumers.

The key configuration points are (all below is of course not strict):

  1. Change output of angular cli to be dist-demo
  2. Change ng-packagr output folder to be dist-lib
  3. Add the repository name to be the base url for the package.json build: ng build --prod --base-href=/<your-repo-name-here>/
  4. Adapt .gitignore to include the dist folders above

and finally configure travis to deploy both demo to github pages and the library to npm repo with something similar to:

language: node_js

node_js:
  - '8'

script:
  - npm run build
  - cp dist-demo/index.html dist-demo/404.html
  - npm run packagr

before_deploy:
  - cd dist-lib

deploy:
  - provider: npm
    email: <your-email-here>
    api_key: $NPM_TOKEN
    skip_cleanup: true
    on:
      tags: true
  - provider: pages
    local-dir: dist-demo
    skip-cleanup: true
    github-token: $GITHUB_TOKEN
    keep-history: true
    on:
      branch: master

Here you go: the repo, the demo and the library with a minimal effort.

Would be quite good if future angular/cli could also generate a travis config for the library, because from my experience travis is not that newbie-friendly.

smnbbrv avatar Mar 22 '18 13:03 smnbbrv

The only problem that i'm facing with ng-packagr is that it compiles everything before-hand, so it's not possible to add specific styles or overwrite SCSS variables for specifics projects.

To do like angular-material it will be necessary to remove the view encapsulation, that will be a huge refactoring of the components/scss.

I don't think if there's a solution this case 😞

picheli20 avatar Mar 22 '18 16:03 picheli20

Use CSS variables ;-)

oliverjanik avatar Mar 23 '18 08:03 oliverjanik

Unfortunately, @oliverjanik, there are some cases in which we need to support browsers that don't support CSS variables like IE 11 (enterprise apps) 😞

Kurtz1993 avatar Apr 06 '18 03:04 Kurtz1993

The impossibility of scss / whatsoever styles variables configuration does not come from ng-packagr. This is a limitation of AoT which needs to compile everything beforehand. Thus, it is also not a problem which Angular CLI can / should solve.

The only visible (to me) solution of this problem is another workaround on top of the ViewEncapsulation on the angular core side, which will allow to support style variables that are coming from angular (kinda component variables to styles injection). In fact, angular would need to bind data not to HTML only but to the CSS as well.

Looking at all this from the prospective of angular core, I would rather wait for CSS variables in major browsers and do nothing instead of building a predictably dead piece of the framework.

As a result, extendng what @oliverjanik has said, use CSS variables or wait until they are supported in the major browsers :) For now, don't use the component styles.

smnbbrv avatar Apr 06 '18 03:04 smnbbrv

I just read the update a few hours ago to the angular CLI, looks like we'll finally get this feature :+1:

Library support! That was one of the most requested feature. You can generate a new library in your project by using ng generate library <name>.

geocine avatar Apr 09 '18 13:04 geocine

@geocine any hints as to how to get this installed? I just installed latest cli but doesn't look like it's available yet.

Update: I see it in 6.0.0 rc2 (https://github.com/angular/angular-cli/releases) but it doesn't seem to be working yet.

ivanirjoao avatar Apr 11 '18 13:04 ivanirjoao

@ivanirjoao the library functionality is still in release candidate form; not fully released. So yarn add @angular/cli@latest will still give you 1.7.4 but yarn add @angular/cli@next should give you the release candidate.

See all available versions: https://www.npmjs.com/package/@angular/cli

benjamincharity avatar Apr 11 '18 13:04 benjamincharity

Hello!

A new library can be created with the ng generate library command only? And create application project before.

I think it would be convenient to create a new Lib project in this way (in addition to generate): ng new <name> --type library

aastrouski avatar Apr 13 '18 09:04 aastrouski

+1 for ng new <name> --type library as @aastrouski suggested

iztsv avatar May 01 '18 10:05 iztsv

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.

filipesilva avatar May 02 '18 23:05 filipesilva

Does it support sub-library?

For example @angular/common/http or @angular/core/testing

Thanks.

On Thu, 3 May 2018 at 2:22 Filipe Silva [email protected] wrote:

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.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/angular/angular-cli/issues/6510#issuecomment-386150875, or mute the thread https://github.com/notifications/unsubscribe-auth/AFIN3XLCMpv9hR04NamAEKAfwSLjFZwiks5tuj-ZgaJpZM4Nqsq5 .

shlomiassaf avatar May 02 '18 23:05 shlomiassaf

Does it support sub-library?

Answer: Yes, by using NX and some changes to ng-packer json files and tsconfig files.

shlomiassaf avatar May 16 '18 23:05 shlomiassaf