[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.
@Flixt I want to point out that https://github.com/gonzofish/angular-librarian is also out there--similar to generator-angular2-library
It's a WIP, but it's been working for my day-to-day
@devoto13 How do you handle external templates inside components ? simple-ui-lib mentioned in the talk uses inline templates.
@kkganesan Currently I use only inlined templates and styles. Not very convenient option, but it works for now.
I like how https://github.com/filipesilva/angular-quickstart-lib is made because it builds library to correct angular module format and it has integration tests running in jit and aot modes, but it uses crappy SystemJs. I rewrote development build process to use Webpack for demo app and unit tests in this simple library project https://github.com/anjmao/ang-select.
@robwormald any update on this?
Hey guys. Just wanted to share with you a solution which suits the company needs I am currently working. I managed to make cli work as a mono-repo with multiple apps and a shared library of modules. The current setup supports lazy loading, AOT, SCSS and a custom path ("@shared/") for my shared modules. Although this setup is considered a hack and probably does not follow the Angular Package Format , it does suit our needs. It is simple and easy to work with as you can have multiple apps that can be served/built independently that share your custom components and the same node_modules. The basic repo structure is:
- src --- app1 --- app2 --- etc --- shared ------ components ------ providers ------ etc
- dist --- app1 --- app2 --- etc
- node_modules
A repo showing the setup after request: Github repo
I do want to thank the Angular team for this fantastic framework as I enjoy working with it everyday. Continue the great work guys :)
Thanks for sharing your solution @nekkon . Do you have a GitHub repo showing a setup of this structure?.
I have updated the Github repo with more functionality after several requests:
Angular CLI with Library support (1.2.7)
This project was generated with Angular CLI. It is an extended version of a new app generated with ng new. It adds Library support for multiple apps in a mono-repo.
This starter is a result of many workarounds in order to make angular-cli work with a shared library of components/services/modules etc.
Currently supports:
Serving multiple apps at the same time Production build of multiple apps (with AOT) Shared Library of components/modules ( can be shared between each app with @shared/ ) Shared assets folder and polyfills. ( can be shared between each app ) Shared SCSS. ( can be shared between each app ) lazy loading of Shared modules Unit tests for each app E2E tests for each app Custom commands to make your life easier and everything else you would normally be able to do with an app generated with ng new. Feel free to create an issue for a request or to fix something.
Star and support this project if you like it, to help it stay alive and maybe even be added as a boilerplate/starter to angular-cli (e.x. ng new app-name --template library).
@hansl any updates from the Angular team on this?
@yordis @piernik @desfero @RSginer @samherrmann @benjamincharity @gracegotlost @rafmagns-skepa-dreag Hey guys. Till the Angular-CLI team officially provides you with a library option you can try out library. Feel free to provide feedback, make requests or report issues. I will be updating it constantly cause I use it at work. (current version 1.3.2)
@nekkon Just to unterstand ... angular-cli-library shares common code from TypeScript sources with a compilerOptions.paths mapping, right? So in effect, each app links against sources and re-builds the shared library. The shared library is then not intended to be published on a npm registry, right?
@dherges "angular-cli-library shares common code from TypeScript sources" -> Yes. It uses modules/code located in the src folder, either in your app or from a library (shared code). The library can also be published on an npm registry if you want to. I could add an example to the repo. Because I do not want to pollute this thread, please provide feedback, ask questions, make requests or report issues in the repo
@nekkon Yes and no. If published to npm registries, it should be in the Angular Package Format and this involves a series of different build steps and tools.
@dherges The library can be published to npm registry. I have added an example where the shared library is imported from npm registry (Example2). Imported modules can be lazy loaded in other projects and are aot compatible. From my understanding, this thread is talking about a library that can be imported into other projects. I do not understand you. Why does a library need build steps and tools?
@nekkon would you create some video explaining how to use it and you can add to the video some questions asked already? Some people like me are more visual, just asking, no a big deal
@yordis I could do something like that but it would take me some time to make the video. I'll try to find some time during the weekend.
Fine!
I was mainly speaking about angular package format which is the recommended way of publishing a library - as opposed to publishing source files leaving the typescript compilation, template syntax & type checking, styles preprocessing like vendor-prefixing or scss/less preprocessing to the build tool of the lib consumer.
Cheers, David
On 24. Aug 2017, at 22:44, Nektarios [email protected] wrote:
@dherges The library can be published to npm registry. I have added an example where the shared library is imported from npm registry (Example2). It can also be lazy loaded in other projects and is aot compatible.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.
@dherges Thanks. I will add what you mentioned is missing ( typescript compilation, template syntax & type checking, styles preprocessing like vendor-prefixing or scss/less preprocessing ), although it can be used for most use cases as it is.
When people talk about adding library support, they're usually talking about a pre-compilation step and consuming it like that.
Just want to add my use-case that we need shared code that isn't pre-compiled. We want to be able to provide Core components that consume Images and SCSS variables. Depending on the app served, the SCSS variables provided to those Core components will be different.
We have a white-label website and then we have around 10 "skins" or "brands" or "themes" that only need to change the colours and images. Imagine you need to create 2 applications: "Coca Cola" and "Pepsi". The only thing that changes is the colours and images. We could achieve this with the monorepo stuff though I think
@intellix I recently experimented with project scaffolding for an Angular monorepo. The generated projects have a structure similar to the Angular repo or the structure proposed by Lerna, thus facilitating
- building libraries in a monorepo
- building apps from feature packages
I've outlined my main motivations for a monorepo approach in #6083 but repeat some here. (edit: see better explanation below)
@intellix I, too, consider a theme to be a separate package for the same reasons you mentioned. When generating a project you can choose to scaffold a theme-package, too.
From what I've seen so far I can recommend ng-packagr by @dherges to build packages conformant to Angular Package Format (no enterprise experience here, though).