1 | # ng-packagr
|
2 |
|
3 | > Compile and package Angular libraries in Angular Package Format (APF)
|
4 |
|
5 |
|
6 | [![npm](https://img.shields.io/npm/v/ng-packagr.svg?style=flat-square)](https://www.npmjs.com/package/ng-packagr)
|
7 | [![npm License](https://img.shields.io/npm/l/ng-packagr.svg?style=flat-square)](https://github.com/ng-packagr/ng-packagr/blob/main/LICENSE)
|
8 | [![CircleCI](https://img.shields.io/circleci/project/github/ng-packagr/ng-packagr/main.svg?label=Circle%20CI&style=flat-square)](https://circleci.com/gh/ng-packagr/ng-packagr)
|
9 |
|
10 | [![GitHub stars](https://img.shields.io/github/stars/ng-packagr/ng-packagr.svg?label=GitHub%20Stars&style=flat-square)](https://github.com/ng-packagr/ng-packagr)
|
11 | [![npm Downloads](https://img.shields.io/npm/dw/ng-packagr.svg?style=flat-square)](https://www.npmjs.com/package/ng-packagr)
|
12 | [![Renovate enabled](https://img.shields.io/badge/renovate-enabled-brightgreen.svg?style=flat-square)](https://renovateapp.com/)
|
13 |
|
14 | ## Installation
|
15 |
|
16 | ```bash
|
17 | npm install -D ng-packagr
|
18 | ```
|
19 |
|
20 | ## Usage Example
|
21 |
|
22 | Let's walk through a _getting started_ that'll build an Angular library from TypeScript sources and create a distribution-ready npm package:
|
23 | create a `ng-package.json` file and run `ng-packagr -p ng-package.json`
|
24 | – Here we go:
|
25 |
|
26 | ```json
|
27 | {
|
28 | "$schema": "./node_modules/ng-packagr/ng-package.schema.json",
|
29 | ...
|
30 | }
|
31 | ```
|
32 |
|
33 | You can easily run _ng-packagr_ through a npm/yarn script:
|
34 |
|
35 | ```json
|
36 | {
|
37 | "scripts": {
|
38 | "build": "ng-packagr -p ng-package.json"
|
39 | }
|
40 | }
|
41 | ```
|
42 |
|
43 | Now, execute the build with the following command:
|
44 |
|
45 | ```bash
|
46 | $ yarn build
|
47 | ```
|
48 |
|
49 | The build output is written to the `dist` folder, containing all those _binaries_ to meet the Angular Package Format specification.
|
50 | You'll now be able to go ahead and `npm publish dist` your Angular library to the npm registry.
|
51 |
|
52 | Do you like to publish more libraries?
|
53 | Is your code living in a monorepo?
|
54 | Create one `package.json` per npm package, run _ng-packagr_ for each!
|
55 |
|
56 | ## Features
|
57 |
|
58 | * :gift: Implements [Angular Package Format](https://angular.io/guide/angular-package-format)
|
59 | * :checkered_flag: Bundles your library in FESM2022
|
60 | * :school_satchel: npm package can be consumed by [Angular CLI](https://github.com/angular/angular-cli), [Webpack](https://github.com/webpack/webpack), or ESM Bundlers
|
61 | * :dancer: Creates type definitions (`.d.ts`)
|
62 | * :mag_right: Creates [scoped and non-scoped packages](https://docs.npmjs.com/misc/scope) for publishing to npm registry
|
63 | * :surfer: Inlines Templates and Stylesheets
|
64 | * :sparkles: CSS Features
|
65 | * :camel: Runs [SCSS](http://sass-lang.com/guide) preprocessor, supporting custom include paths
|
66 | * :monkey: Adds vendor-specific prefixes w/ [autoprefixer](https://github.com/postcss/autoprefixer#autoprefixer-) and [browserslist](https://github.com/ai/browserslist#queries) — just tell your desired `.browserslistrc`
|
67 | * :tiger: Embed assets data w/ [postcss-url](https://github.com/postcss/postcss-url#inline)
|
68 |
|
69 |
|
70 | ## How to…
|
71 | - [Copy Assets](docs/copy-assets.md)
|
72 | - [Embed Assets in CSS](docs/embed-assets-css.md)
|
73 | - [Managing Dependencies](docs/dependencies.md)
|
74 | - [Change the Entry File of a Library](docs/entry-file.md)
|
75 | - [Change Configuration Locations](docs/configuration-locations.md)
|
76 | - [Override tsconfig](docs/override-tsconfig.md)
|
77 | - [Use PostCSS](docs/postcss-config.md)
|
78 | - [Add Style Include Paths](docs/style-include-paths.md)
|
79 | - [Package Secondary Entrypoints (sub packages)](docs/secondary-entrypoints.md)
|
80 |
|
81 | ## Knowledge
|
82 |
|
83 | [Angular Package Format documentation](https://angular.io/guide/angular-package-format)
|
84 |
|
85 | Packaging Angular Libraries - Jason Aden at Angular Mountain View Meetup ([Jan 2018, 45min talk](https://www.youtube.com/watch?v=QfvwQEJVOig&t=3612s))
|
86 |
|
87 | Create and publish Angular libs like a Pro - Juri Strumpflohner at NG-BE ([Dec 2017, 30min talk](https://youtu.be/K4YMmwxGKjY))
|
88 |
|
89 | [![Juri Strumpflohner - Create and publish Angular libs like a Pro](https://img.youtube.com/vi/K4YMmwxGKjY/0.jpg)](https://youtu.be/K4YMmwxGKjY)
|
90 |
|
91 | Packaging Angular - Jason Aden at ng-conf 2017 ([28min talk](https://youtu.be/unICbsPGFIA))
|
92 |
|
93 | [![Packaging Angular - Jason Aden](https://img.youtube.com/vi/unICbsPGFIA/0.jpg)](https://youtu.be/unICbsPGFIA)
|
94 |
|
95 |
|
96 | 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](https://youtu.be/Tw8TCgeqotg))
|
97 |
|
98 | [![Juri Strumpflohner - Create & Publish Angular Libs like a PRO at ngVikings](https://img.youtube.com/vi/Tw8TCgeqotg/0.jpg)](https://youtu.be/Tw8TCgeqotg)
|
99 |
|
100 | ## Contributing to ng-packagr
|
101 |
|
102 | [General contribution guidelines](./CONTRIBUTING.md)
|
103 |
|
104 | 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](./docs/DESIGN.md).
|
105 |
|
106 | To orchestrate the different tools, ng-packagr features a [custom transformation pipeline](docs/transformation-pipeline.md#a-transformation-pipeline). The transformation pipeline is built on top of RxJS and Angular Dependency Injection concepts.
|