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

Ok, with PR #8643 we should be able to make good progress.

shlomiassaf avatar Nov 27 '17 02:11 shlomiassaf

@shlomiassaf Yes, it goes down to the TypeScript transformations which is a sync API. So from there, I chose to go two passes over the *.ts sources.

https://github.com/dherges/ng-packagr/commit/4753066ba7a75e6d570d0ce45052252a56b97214

dherges/ng-packagr#279

dherges avatar Nov 28 '17 21:11 dherges

it's not really the typescript transformations but more the angular compiler implementation.

The compiler-cli does this split into 2 passes internally thus bypassing the sync limitation of TS. So first pass will load all resources.

ngc -p will not do async, so it up to the user to do so...

The PR I created (#8643) should solve this

shlomiassaf avatar Nov 28 '17 21:11 shlomiassaf

Just wanted to add some comments here.

In my current project we have multi-app angular cli application, which consists of 5 apps and 1 components folder, that shares all the common components between app.

Previously we've used few docker containers with mounted components folder in order to develop all the apps and see changes immediately during development.

After some time we decided to move sources into one single multi-app (thought it will be more flexible). But we ran into the problem, that all configuration files and all apps must be inside of the same folder, i.e. we must have 10 configuration files (1 for app and one for spec) in the same folder + every config file of the app must exclude all the other apps from compilation. We've found that unfriendly, cause cli restricts us and it doesn't give a chance to use other infrastructure. To be precise, ngc with aot doesn't support any baseUrl configurations (relative paths etc.).

Angular Package Format is very nice approach, but for development it gives a lot of pain, because you have to compile and install package every time you change it.

serhiisol avatar Jan 10 '18 17:01 serhiisol

@serhiisol I have a monorepo with 10apps. You don't need to exclude all other apps anymore. That has been fixed in a previous version of the CLI. You can use the following in your tsconfig.app.json:

"include": [
        "app1/**/*",
        "shared/**/*"
    ],
    "exclude":[
         "**/*.spec.ts"
    ]

nekkon avatar Jan 11 '18 08:01 nekkon

could be, but you can't keep configuration files in the application sources itself, they have too stay one level up with all the other sources (so like 10apps * 2 config files = 20 tsconfig files, which is way strange to see). Besides that you can't have components folder (with all the components, that are shared between apps) if you'll move config files into app sources folder + aot won't work :)

serhiisol avatar Jan 11 '18 09:01 serhiisol

See https://github.com/nrwl/nx-examples/blob/master/.angular-cli.json#L59-L90 and https://github.com/nrwl/nx-examples/blob/master/tsconfig.json#L17-L22

dherges avatar Jan 11 '18 12:01 dherges

@dherges Does AOT compilation work for you this case? I had similar setup and JIT compilation worked as charm but AOT always complains:

ERROR in ./apps/calculator/src/main.ts
Module not found: Error: Can't resolve './../../../$$_gendir/apps/calculator/src/app/app.module.ngfactory' in '/Users/serhii.sol/Development/mono-app/apps/calculator/src'
resolve './../../../$$_gendir/apps/calculator/src/app/app.module.ngfactory' in '/Users/serhii.sol/Development/mono-app/apps/calculator/src'
  using description file: /Users/serhii.sol/Development/mono-app/package.json (relative path: ./apps/calculator/src)

PS. It seems like this approach doesn't work with lazy-routes (loadChildren)

serhiisol avatar Jan 11 '18 15:01 serhiisol

@serhiisol There are ways to make aot and lazy loading work properly (with workarounds as in a repo I have created https://github.com/nekkon/angular-cli-library) but I agree it is not the right way to go or to have 20tsconfig files. I think all this is until a final proper solution/way is given by the Angular team for how to have a monorepo of multiple apps with a shared library of components (if that ever happens cause it depends on how important they feel it is). I haven't checked https://github.com/nrwl/nx yet, it could be a good solution.

nekkon avatar Jan 11 '18 18:01 nekkon

What's the latest status? Are there docs for packaging libraries, yet? This is a very long thread.

oliverjanik avatar Jan 17 '18 04:01 oliverjanik

Check this Talk: Juri Strumpflohner - Create and publish Angular libs like a Pro by @juristr

It covers most of the Docs using rollup and some other tools.

leocaseiro avatar Jan 17 '18 04:01 leocaseiro

So basically... Year and a half since the original suggestion was posted and still no official solution to what should be a fundamental competency for a component framework. 👎

oliverjanik avatar Jan 18 '18 10:01 oliverjanik

NgPackagr has been an excellent tool to support Angular Library development

matheo avatar Jan 18 '18 20:01 matheo

NgPackagr has been an excellent tool to support Angular Library development

no webpack support, so no require.context, webpack loaders and all this stuff

artaommahe avatar Jan 18 '18 20:01 artaommahe

@artaommahe Webpack is not fit for library building, it's a known issue:

  • https://stackoverflow.com/questions/43219030/what-is-flat-bundling-and-why-is-rollup-better-at-this-than-webpack
  • https://nolanlawson.com/2016/08/15/the-cost-of-small-modules/

But since Webpack is still evolving this situation may change in future.

trotyl avatar Jan 19 '18 03:01 trotyl

@artaommahe Webpack is not fit for library building, it's a known issue:

non-optimal bundle size and content is a smaller problem for us than inability to inline images/svgs to lib bundle )

artaommahe avatar Jan 19 '18 08:01 artaommahe

sometimes I just feel like maybe we should just use git submodules 😂

neo avatar Jan 19 '18 14:01 neo

Ok as far as I understood this thread, there is multiple packaging tools/strategies or at least starters to start with but I'm still missing one thing. How to actually develop those libs if I can not see a change instantly in my app where this lib is used?

I have a case where I have one app, which uses 5 different libraries. Ones are fairly straight forward and could develop them with good test coverage without testing them inside an app but others are fairly complex and dependent on a few of those 5 libs so without linking/using them together in an app I can not see a way how to develop them? Before Angular 5 I could npm link all of those projects together (they are just plain git repository projecs, basically an apps generated with ng new) and everything just worked. But since Angular 5 I can no longer npm link projects in an Angular 5 app if they are not following APF.

I can develop a build procedure, mono repo, anything that is needed for producing APF compatible libraries with some tool listed in this thread, but how do I develop them? The only way I see to support my case is to develop a process which will build the project into APF compatible lib on every change and link all of them together in an app. But I'm not sure how fast this is going to be, and also it will take some time to develop it in the first place so I'm not very interested in this approach. Is this really the only way, or am I missing something?

metodribic avatar Jan 22 '18 14:01 metodribic

@metodribic Have you looked at the solution provided by @vsavkin and team at Nrwl - I think this has been mentioned before in this thread.

We are currently using this for a large enterprise application with 9 internal libraries, running approx 4000+ tests, working with a team of 15 developers. I'm happy to talk through our workflow and tooling if you are interested - unfortunately I can't share our code.

mattem avatar Jan 22 '18 16:01 mattem

@mattem I'm interested, if you do so, add me please :)

matheo avatar Jan 22 '18 19:01 matheo