CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-ng-packagr

Compile and package Angular libraries in Angular Package Format (APF)

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

ng-packagr

ng-packagr is a comprehensive build tool specifically designed for compiling and packaging Angular libraries according to the Angular Package Format (APF). It automates the complex process of creating distribution-ready npm packages from TypeScript sources, handling bundling, TypeScript definitions, template/stylesheet processing, and ensuring compatibility with modern Angular build systems.

Package Information

  • Package Name: ng-packagr
  • Package Type: npm
  • Language: TypeScript
  • Installation: npm install ng-packagr

Core Imports

import { ngPackagr, NgPackagr, NgPackagrOptions } from "ng-packagr";
import { build, execute, version } from "ng-packagr";

For CommonJS:

const { ngPackagr, build, execute, version } = require("ng-packagr");

Basic Usage

Programmatic API

import { ngPackagr } from "ng-packagr";

// Basic build
await ngPackagr()
  .forProject('./ng-package.json')
  .build();

// Build with options
await ngPackagr()
  .forProject('./ng-package.json')
  .build({
    watch: false,
    cacheEnabled: true
  });

// Watch mode
ngPackagr()
  .forProject('./ng-package.json')
  .watch()
  .subscribe();

CLI Usage

# Basic build
ng-packagr -p ng-package.json

# Watch mode
ng-packagr -p ng-package.json -w

# Custom TypeScript config
ng-packagr -p ng-package.json -c tsconfig.lib.json

Architecture

ng-packagr is built around several key architectural components:

  • Transform Pipeline: RxJS-based transformation pipeline that processes the build graph
  • Dependency Injection: Uses injection-js for modular, testable architecture
  • Build Graph: Represents package and entry point dependencies as a traversable graph
  • File System Abstraction: Caching and file watching capabilities for incremental builds
  • Configuration System: JSON schema-validated configuration for packages and entry points

Capabilities

Programmatic API

Core programmatic interface for building Angular libraries programmatically from Node.js applications or build scripts.

function ngPackagr(): NgPackagr;

class NgPackagr {
  forProject(project: string): NgPackagr;
  withOptions(options: NgPackagrOptions): NgPackagr;
  withTsConfig(defaultValues: ParsedConfiguration | string): NgPackagr;
  withProviders(providers: Provider[]): NgPackagr;
  withBuildTransform(transform: InjectionToken<Transform>): NgPackagr;
  build(options?: NgPackagrOptions): Promise<void>;
  watch(options?: NgPackagrOptions): Observable<void>;
  buildAsObservable(): Observable<void>;
}

Programmatic API

Command System

Command interface for executing build operations with unified error handling and promise-based execution.

interface Command<Arguments, Result> {
  (args?: Arguments): Result | Promise<Result>;
}

function execute<A, R>(command: Command<A, R>, args?: A): Promise<R>;

const build: Command<CliArguments, void>;
const version: Command<any, Promise<void>>;

Commands

Configuration System

Comprehensive configuration system supporting ng-package.json and ng-entrypoint.json files with JSON schema validation.

interface NgPackagrOptions {
  watch?: boolean;
  cacheEnabled?: boolean;
  cacheDirectory?: string;
  poll?: number;
}

interface CliArguments {
  project: string;
  watch?: boolean;
  config?: string;
  poll?: number;
}

Configuration

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/ng-packagr@20.2.x
Publish Source
CLI
Badge
tessl/npm-ng-packagr badge