3

Imagine I have a setting in environment that could be true or false for different envs.

And I have an abstract service and two implementations:

@Injectable()
export abstract class TestCommonService {
  protected abstract uniqueId: string;
}
export class TestAService {  
  protected uniqueId = 'test_a';
}
export class TestBService {  
  protected uniqueId = 'test_b';
}

I'm providing this in a module:


{ provide: TestCommonService,
  useFactory: () => environment.feature ? new TestAService() : new TestBService()
}

Is there any way to exclude unnecessary service from the bundle?

Since we know in a build time, if the env property is true or false, I believe, we can do something about it.

I've tried to do the same with @Injectable({providedIn: 'root', useFactory: ...}) but it does not exclude unnecessary service from a bundle as well.

ectuser
  • 131
  • 1
  • 1
  • 11

0 Answers0