Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

Angular Package Format (APF) is the package structure and metadata Angular uses to distribute framework and library code through npm. It gives TypeScript, package resolvers, and build tools predictable public imports, JavaScript modules, and type declarations. If you publish an Angular library, build it with Angular CLI and ng-packagr, expose a deliberate public API, and use partial compilation so consuming applications can compile it with their Angular version.

What is the Angular Package Format?

APF is Angular’s specification for the files and metadata in an npm package. Angular packages such as @angular/core and many third-party libraries use it. It is not a separate runtime or framework: it describes how a package is organized and how tools find the code and types consumers import. Angular evolves APF alongside Angular major versions, so package authors should follow the current guide rather than assume the format never changes. Angular Package Format

The format is designed to work with Angular CLI and other JavaScript build tools. Its predictable entrypoints and module metadata help tools resolve packages, optimize application bundles, and support development workflows.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How an APF package exposes code and types

A package’s package.json is central to resolution. In the current documented format, a simplified package can include flattened JavaScript modules in fesm2022/, declarations in types/, and source maps. The manifest’s exports map identifies public entrypoints and maps them to runtime files and TypeScript declarations. It can also expose non-JavaScript assets through conditional exports. The exact contents of a real package depend on its entrypoints and build.

  • type: "module" identifies the package as using ECMAScript module syntax.
  • exports is the modern map for package entrypoints and their resolved files.
  • sideEffects communicates whether files have side effects, information optimizers can use when removing unused code.
  • module and typings are legacy resolution fields shown for compatibility with tools that do not use exports; Angular describes them as deprecated as support for exports rolls out.

Angular’s current guide documents ES2022 as the JavaScript language level for the package output. That is distinct from ESM: ESM describes the import/export module system, while ES2022 describes language features. Angular CLI and other application build tools can down-level output for the browser targets configured by an application. Angular Package Format documentation

What is an Angular package entrypoint?

An entrypoint is a public import path into a package. The primary entrypoint is the package root; secondary entrypoints provide additional public subpaths, such as @angular/core/testing or my-lib/button. Consumers should use these documented paths rather than deep-importing implementation files, which can change without being part of the supported API.

Choose entrypoints around coherent capabilities

Entrypoints define API boundaries and can also be lazy-loading boundaries: bundlers often split code at ES-module boundaries. APF commonly flattens each entrypoint into one ES module, so a single entrypoint can limit the granularity available for splitting. Organize entrypoints as the smallest logically connected groups that make sense; a library with one focused purpose may appropriately have just one.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Expose and connect entrypoints deliberately

In a CLI-generated library, public-api.ts defines what consumers can import. To add a secondary entrypoint, create a directory with its own ng-package.json and public API file; ng-packagr derives the package subpath from that directory. When one entrypoint refers to another, use the package import path, not a relative path between entrypoint directories, and avoid circular dependencies. Creating libraries Creating secondary entrypoints

Why published libraries should use partial compilation

Angular libraries intended for independent publication should use partial compilation. It emits a stable intermediate representation instead of tying the library to fully compiled instructions for one exact Angular runtime version. During an application build, Angular CLI converts that representation to fully compiled code using the consumer application’s Angular compiler. This lets a published library be consumed across supported Angular versions without publishing version-specific full-Ivy output. Angular Package Format documentation

The Angular compiler options distinguish the two modes:

  • partial is the stable intermediate format intended for published libraries that may be used by applications on different Angular versions.
  • full generates fully AOT-compiled output for the Angular version being used. It can suit a library built alongside its application with the same Angular version, for example in a monorepo, when version skew is not a concern.

Do not treat full-Ivy output as a general publishing optimization. The generated instructions are version-specific and are not a public API. Angular compiler options

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How to build and publish an Angular library

Angular’s documented workflow uses Angular CLI and ng-packagr. The library builder uses ng-packagr to produce an APF-compliant package; the current CLI build documentation identifies the builder as @angular/build:ng-packagr. Use a production build for distribution, inspect the generated package, and publish that output to npm. Creating libraries CLI build

  1. Generate or configure the library. Use the Angular CLI library workflow. Its primary package configuration is ng-package.json, which identifies the library entry file, commonly src/public-api.ts.
  2. Define the public API. Export supported symbols from the public API file. Add secondary entrypoints only for distinct, coherent capabilities, each with its own ng-package.json and public API file.
  3. Set compilation and dependency metadata. Use partial compilation for an independently published package. Declare Angular framework packages the library uses as peer dependencies, and set a peer version range that reflects the Angular versions the library intends to support.
  4. Build for distribution. Run the library’s production build using the CLI library builder and review the resulting dist package before publishing.
  5. Publish the production package. Publish the built package to npm. Consumers install it with their package manager and import its documented public paths; for many libraries, ng add can also run package schematics to configure project integration.

Angular framework packages should be peers rather than ordinary library dependencies so the application and library use the same Angular module instance. Bundling Angular as a regular dependency can introduce a duplicate instance and runtime problems. Library peer dependencies

The generated package can include assets such as Sass mixins or CSS, but these must be exposed through package exports if consumers are expected to import them. Check the final package for the files and declarations your documentation promises. Managing library assets

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

How to evaluate an Angular package

When reviewing a library you did not build, inspect the published package and its manifest against the intended consumer use:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Public API: Are supported import paths documented and logically grouped, or does usage require brittle deep imports?
  • Compilation compatibility: Is an independently published library partial-compiled, and does its Angular peer dependency range match the versions it claims to support?
  • Resolver metadata: Does exports map each public path to runtime code and declarations? Are legacy fields present only when compatibility needs justify them?
  • Optimization metadata: Is sideEffects accurate, and can consumers import only the entrypoints they need?
  • Distribution completeness: Does the production package contain declarations, assets, README files, and other files promised to consumers?
  • Dependency ownership: Are Angular framework packages declared as peers where required?

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.