[RFC] Library Support and Boilerplate Comment Thread
As a follow up for https://github.com/angular/angular-cli/issues/1692#issuecomment-304970595.
Continue the conversion here.
@Holzberg can you be more specific with what you mean by "errors out"? (Maybe better to open an issue there for this conversation :))
@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 The video is up here: https://youtu.be/QfvwQEJVOig?t=1h12s
Waiting for an "official" process also. Submoduling an angular project through git submodule works in the mean time..
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 please post the video here when uploaded, very very needed, thanks :)
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
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):
- Change output of angular cli to be
dist-demo - Change ng-packagr output folder to be
dist-lib - Add the repository name to be the base url for the package.json build:
ng build --prod --base-href=/<your-repo-name-here>/ - 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.
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 😞
Use CSS variables ;-)
Unfortunately, @oliverjanik, there are some cases in which we need to support browsers that don't support CSS variables like IE 11 (enterprise apps) 😞
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.
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 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 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
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
+1 for ng new <name> --type library as @aastrouski suggested
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.
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 .
Does it support sub-library?
Answer: Yes, by using NX and some changes to ng-packer json files and tsconfig files.