0

We're trying to optimize the bundle sizes for our very feature rich Angular app. We use @ngrx/store for state management.

I've been around the block a few times - We're already using feature modules properly, they're in lazy loaded routes. However, sometimes feature A and feature B, both use feature C's StoreModule.

These StoreModules (Where it is shared between two separate lazy features) end up in the main.js bundle.

What magic must I work to expel them from main.js?

Bryan Rayner
  • 4,172
  • 4
  • 26
  • 38
  • Without knowing your concrete project structure, I guess an excessive use of `@Injectable({ providedIn: 'root' })` causes this problem. You can try to decorate the modules with `@Injectable()` and provide them there, where you need them, e.g. in `@Module({ providers: ... })` – hmartini Mar 25 '23 at 18:07
  • @Injectable({providedIn: 'root' }) is the documented way to make sure services are singletons. I need them to be singletons - So there must be a way to encourage them to be loaded as separate lazily loaded modules, not just show up in main for "efficiency". – Bryan Rayner Mar 27 '23 at 13:47

0 Answers0