ng-packagr

Transpile your component libraries to Angular Package Format.

Github星跟蹤圖

ng-packagr

Transpile your libraries to Angular Package Format

npm
npm License
Conventional Commits
CircleCI

GitHub contributors
GitHub stars
npm Downloads
Renovate enabled

Credits

Contributors

This project exists thanks to all the people who contribute. [Contribute].

Installation

npm install -D ng-packagr

Usage Example

Let's walk through a getting started that'll build an Angular library from TypeScript sources and create a distribution-ready npm package:
create a package.json file, add the custom ngPackage property, and eventually run ng-packagr -p package.json
– Here we go:

{
  "$schema": "./node_modules/ng-packagr/package.schema.json",
  "name": "@my/foo",
  "version": "1.0.0",
  "ngPackage": {
    "lib": {
      "entryFile": "public_api.ts"
    }
  }
}

Note 1: Paths in the ngPackage section are resolved relative to the location of the package.json file.
In the above example, public_api.ts is the entry file to the library's sources and must be placed next to package.json (a sibling in the same folder).

Note 2: referencing the $schema enables JSON editing support (auto-completion for configuration) in IDEs like VSCode.

You can easily run ng-packagr through a npm/yarn script:

{
  "scripts": {
    "build": "ng-packagr -p package.json"
  }
}

Now, execute the build with the following command:

$ yarn build

The build output is written to the dist folder, containing all those binaries to meet the Angular Package Format specification.
You'll now be able to go ahead and npm publish dist your Angular library to the npm registry.

Do you like to publish more libraries?
Is your code living in a monorepo?
Create one package.json per npm package, run ng-packagr for each!

Features

  • :gift: Implements Angular Package Format
    • :checkered_flag: Bundles your library in FESM2015, FESM5, and UMD formats
    • :school_satchel: npm package can be consumed by Angular CLI, Webpack, or SystemJS
    • :dancer: Creates type definitions (.d.ts)
    • :runner: Generates Ahead-of-Time metadata (.metadata.json)
    • :trophy: Auto-discovers and bundles secondary entry points such as @my/foo, @my/foo/testing, @my/foo/bar
  • :mag_right: Creates scoped and non-scoped packages for publishing to npm registry
  • :surfer: Inlines Templates and Stylesheets
  • :sparkles: CSS Features

How to…

Advanced Use Cases

Examples and Tutorials

A great step-by-step example of making an Angular CLI project with a library distributed separate from the app, by Jason Aden

Nikolas LeBlanc wrote a tutorial on building an Angular 4 Component Library with the Angular CLI and ng-packagr

Here is a demo repository showing ng-packagr and Angular CLI in action.

What about ng-packagr alongside Nx Workspace? Well, they work well together!

Further user questions and issue-driven documentation

We keep track of user questions in GitHub's issue tracker and try to build a documentation from it.
Explore issues w/ label documentation.

Contributing to ng-packagr

General contribution guidelines

If you like to submit a pull request, you'll find it helpful to take a look at the initial design document where it all started.

To orchestrate the different tools, ng-packagr features a custom transformation pipeline. The transformation pipeline is built on top of RxJS and Angular Dependency Injection concepts.

Knowledge

Angular Package Format v9.0, design document at Google Docs

Packaging Angular Libraries - Jason Aden at Angular Mountain View Meetup (Jan 2018, 45min talk)

Create and publish Angular libs like a Pro - Juri Strumpflohner at NG-BE (Dec 2017, 30min talk)

Juri Strumpflohner - Create and publish Angular libs like a Pro

Packaging Angular - Jason Aden at ng-conf 2017 (28min talk)

Packaging Angular - Jason Aden

Create and publish Angular libs like a Pro - Juri Strumpflohner at ngVikings, this time demoing building Angular libraries with ng-packagr, with NX as well as Bazel (March 2018, 30min talk)

Juri Strumpflohner - Create & Publish Angular Libs like a PRO at ngVikings

主要指標

概覽
名稱與所有者ng-packagr/ng-packagr
主編程語言TypeScript
編程語言TypeScript (語言數: 9)
平台
許可證MIT License
所有者活动
創建於2017-05-17 08:43:27
推送於2025-07-22 10:40:03
最后一次提交
發布數371
最新版本名稱20.2.0-next.0 (發布於 2025-07-16 15:42:58)
第一版名稱v1.0.0-alpha.0 (發布於 2017-05-19 21:42:37)
用户参与
星數1.9k
關注者數48
派生數297
提交數2.6k
已啟用問題?
問題數1106
打開的問題數17
拉請求數1746
打開的拉請求數2
關閉的拉請求數239
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?