I've been working on streamlining my code and reducing the amount of import statements needed everywhere.
So, in index.ts
within my services directory, I created a barrel file:
import { Service1} from "./service1.service";
import { Service2 } from "./service2.service";
import { Service3 } from "./service3.service";
export const commonServices = [
Service1,
Service2,
Service3,
];
This allows me to minimize the import statements in app.module.ts
using the spread operator.
...
import { commonServices } from "./common/services";
@NgModule({
...
providers: [
...commonServices,
]
})
export class AppModule { }
However, when it comes to some.component.ts
, I can't simply use one import statement because the specific services are not barreled in index.ts
.
...
// This doesn't work
// import { Service1, Service2 } from "../../core/services";
// Instead, I have to do this
import { Service1 } from "../../core/services/service1.service";
import { Service2 } from "../../core/services/service2.service";
@Component({
})
export class SomeComponent {
}
Is there a clean and efficient way to configure index.ts
to export the service names as well? Any suggestions?