How to only have secondary entry points in ng-packagr
Asked Answered
G

1

9

I have an Angular CLI library where each component should only be imported through their individual entry-points (like Angular Material) :

import {Foo} from '@myLib/foo
import {Bar} from '@myLib/bar

So I don't want a main entry point in ng-packagr config.

I already have all the secondary entry-points defined and I want to remove the primary entry-point so users cannot just "import {Bar} from '@myLib", but ng-package.json requires an entryFile and when I leave the entryFile empty I get an error

ERROR: Internal error: failed to get symbol for entrypoint

I have to add at least one valid export in the the entryFile.

The Angular Material team seem to have got this right - https://github.com/angular/components/blob/master/src/material/index.ts

Any ideas on how to do this?

Gelman answered 23/1, 2020 at 5:30 Comment(0)
T
15

I'm not sure if this scenario is supported.

I'm using ng-packagr for a similar setup and what seems to work (although not pefect) is the below:

if you have the following structure:

@mylib
├── src
|   ├── public_api.ts
|   └── *.ts
├── ng-package.json
├── package.json
└── foo
|   ├── src
|   |   ├── public_api.ts
|   |   └── *.ts
|   └── ng-package.json
└── bar
    ├── src
    |   ├── public_api.ts
    |   └── *.ts
    └── ng-package.json

if you set your root package.json with the name of the scope

{
  "name": "@myLib"
}

you set your root ng-package.json to this

{
  "$schema": "../../node_modules/ng-packagr/ng-package.schema.json",
  "dest": "../../dist/@myLib"
}

and put an empty object export in your main public_api.ts (that is /src/public_api.ts)

export default {};

then you should get the structure you are looking for

hope it helps

Trapeze answered 13/2, 2020 at 0:13 Comment(1)
Thanks. Using the empty object export does sort it out but I don't really like having dummy objects in my code and it also generates this empty entry point to distGelman

© 2022 - 2024 — McMap. All rights reserved.