6

A very big library I am creating, so naturally I am thinking to modularise the public_api.ts for different huge modules.

But it seems I cannot achieve that via something like this in the root public_api.ts:

export * from "./lib/lib2-m1/public_api";
export * from "./lib/lib2-m2/public_api";

And also the ng-package.json used by ng-packagr is using entryFile which is a singular.

A simple demo to present the case.

Any idea will be appreciated for better modularisation of the big lib.

Hearen
  • 7,420
  • 4
  • 53
  • 63

1 Answers1

6

You can try creating index.ts file with public-api.ts file and use that index file in root public-api.ts file in root public-api.ts

export * from "./lib/lib2-m1/index";
export * from "./lib/lib2-m2/index";

This worked in my project.

Hearen
  • 7,420
  • 4
  • 53
  • 63
Vikash Dahiya
  • 5,741
  • 3
  • 17
  • 24
  • and what if I'd like to have one library but group it inside so then I can do: `import { SomeService } from '@myOrg/lib/services';` and `import { SomeEntity } from '@myOrg/lib/model';` – ciekawy Feb 26 '19 at 17:15
  • you can do it by using both public-api.ts and index.ts together, ex:- export all services from public-api.ts and then export public-api.ts in index.ts file – Vikash Dahiya Feb 27 '19 at 00:56
  • Interesting idea! Just not sure if I understood - considering `public-api.ts` already flattens all the exports - how `index.ts` can provide a subset and how it can be nested / grouped into “sub-modules”? – ciekawy Feb 27 '19 at 01:00
  • the nested/grouped structure is provided by public-api.ts(whatever you export inside this file you can import from the library providing correct path), and the index.ts just make importing syntax easier like `@myOrg/lib/services` – Vikash Dahiya Feb 27 '19 at 01:17