Compile and package a TypeScript library to Angular Package Format
npm install ng-packagr-dev> Transpile your libraries to Angular Package Format










This project exists thanks to all the people who contribute. [Contribute].
Thank you to all our backers! π [Become a backer]
Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor]
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:
``json`
{
"$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.public_api.ts
In the above example, 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:
`json`
{
"scripts": {
"build": "ng-packagr -p package.json"
}
}
Now, execute the build with the following command:
`bash`
$ yarn build
The build output is written to the dist folder, containing all those _binaries_ to meet the Angular Package Format specification.npm publish dist
You'll now be able to go ahead and 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!
* :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).metadata.json
* :runner: Generates Ahead-of-Time metadata ()@my/foo
* :trophy: Auto-discovers and bundles secondary entry points such as , @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
* :camel: Runs SCSS preprocessor, supporting the relative import syntax and custom include paths~
* :elephant: Runs less preprocessor, supports the relative import syntax.browserslistrc`
* :snake: Runs Stylus preprocessor, resolves relative paths relative to ng-package.json
* :monkey: Adds vendor-specific prefixes w/ autoprefixer and browserslist — just tell your desired
* :tiger: Embed assets data w/ postcss-url
#### 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.
Angular Package Format v6.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)

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

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)
