pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/angular/angular/pull/67891/files

media="all" rel="stylesheet" href="https://github.githubassets.com/assets/code-2d31826944fd3be8.css" /> docs: explain library secondary entrypoints by weedorflow · Pull Request #67891 · angular/angular · GitHub
Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions adev/src/content/tools/libraries/creating-libraries.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,64 @@ Anything exported from this file is made public when your library is imported in

Your library should supply documentation \(typically a README file\) for installation and maintenance.

### Creating secondary entrypoints

A secondary entrypoint lets consumers import a distinct subset of your library, for example `my-lib/testing`, without pulling in the entire library bundle.

To create one, follow these steps:

**1. Create the entrypoint directory and files**

Add a subdirectory under your library project with its own `ng-package.json` and `src/public-api.ts`:

```text
projects/my-lib/
ng-package.json
src/public-api.ts
testing/
ng-package.json
src/public-api.ts
```

**2. Configure `ng-package.json`**

In the secondary entrypoint directory, set `entryFile` to point to its public API:

```json
{
"lib": {
"entryFile": "src/public-api.ts"
}
}
```

**3. Export symbols from the public API**

In `testing/src/public-api.ts`, export the symbols you want consumers to access from this entrypoint:

```typescript
export { MockMyLibService } from './mock-my-lib.service';
export { MyLibHarness } from './my-lib.harness';
```

**4. Build the library**

Build with the Angular CLI as usual — ng-packagr automatically discovers and compiles all secondary entrypoints:

```shell
ng build my-lib
```

**5. Use the secondary entrypoint in consuming applications**

After building, consumers import from the secondary entrypoint using its subpath:

```typescript
import { MockMyLibService } from 'my-lib/testing';
```

For more details on how secondary entrypoints are resolved and when to use them, see [Entrypoints and code splitting](tools/libraries/angular-package-format#entrypoints-and-code-splitting) and [Resolution of secondary entry points](tools/libraries/angular-package-format#resolution-of-secondary-entry-points).

## Refactoring parts of an application into a library

To make your solution reusable, you need to adjust it so that it does not depend on application-specific code.
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy