jvandemo / generator-angular2-library

Yeoman generator to create an Angular library
MIT License
752 stars 122 forks source link

Support tree shaking #266

Open rkusuma opened 6 years ago

rkusuma commented 6 years ago

I have created Angular UI components for my project using this generator, but all my library component included in my application bundle (using angular-cli).

How can i have bundle only for the module (from my library) that i import in my application? Like ngx-bootstrap behavior.

import { TooltipModule } from 'ngx-bootstrap/tooltip` 

For example if i'm only using TooltipModule, my application bundle only include TooltipModule from ngx-bootstrap not all modules.

caroso1222 commented 6 years ago

In my view, this feature is out of the scope of this project, at least for now. The reason is because, on one hand, libraries such as ngx-bootstrap, material, ng-bootstrap, primeng, etc, all they expose standalone modules, each one offering an isolated feature, but they all live under the same namespace. Thus, they tend to write more intricate build workflows, or at least, repeating one simple build workflow per entrypoint, or per module as you call it. On the other hand, this generator focuses on libraries that expose one module with a clearly defined scope and functionality.

Look at how ngx-bootstrap distributes their application. It's a folder per module, and each module is not even rolled up which by the way is worse than a rolled up module. The build system scaffolded by this generator was simply not thought to support those kind of libraries.

screen shot 2018-01-20 at 1 16 51 am

It's doable, but I'm really not sure if this is part of the roadmap because the build system would have to be restructured quite a bit to support multi-modules libraries. I think it's out of the scope, though. @jvandemo you got the last word, what's your take on this one?

broweratcognitecdotcom commented 6 years ago

One should be able to support this type of feature modules/main module by manually editing the project files. But If you ask me, the generator should add feature modules for the sample component, etc. and import the feature modules into the main module, to promote correct architecture of the generated library.

izifortune commented 6 years ago

This doesn't follow the angular package format https://docs.google.com/document/d/1CZC2rcpxffTDfRDs6p1cfbmKNLA6x5O-NtkJglDaBVs/edit which will make it harder to consume the library in other scenarios

jasekiw commented 6 years ago

@caroso1222 Why does the project need to be rolled up? Doesn't that break tree shaking since the user project's bundler cannot exclude files?