1

I have a file name service.imports.ts having following code.

export { Http, Response, Headers, RequestOptions } from '@angular/http'
export { Observable } from 'rxjs/Observable'
export { Injectable } from '@angular/core';
export * from 'rxjs/add/operator/map';
export * from 'rxjs/add/operator/catch';

and call that file in my angular 2 service.ts file by

import { Http } from '../service.imports'

As you can see i am only calling Http module and ignoring Response, Headers, RequestOptions.

how angular 2 handles this situation? will it load all the modules mentioned in service.imports.ts or it only loads the modules which are being called where that service.imports.ts is used i.e only Http?

I have the performance concern.

Salman Lone
  • 1,526
  • 2
  • 22
  • 29

1 Answers1

1

No, these imports don't matter. The compilation step will get rid of them.

It would be different if you'd add them to

@NgModule({
  imports: [...],
  declarations: [...],
  bootstrap: [...],
  entryComponents: [...]
})

Using barrels was even an Angular style guide suggestion a while ago, until they discovered it regularly causes issues like Angular 2 DI Error - EXCEPTION: Can't resolve all parameters

Community
  • 1
  • 1
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567