npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cphp-ng4-packagr

v1.7.1

Published

Fork of ng-packagr, Fixed ENONT issue caused by uglify-js

Downloads

11

Readme

ng-packagr

Compile a TypeScript library to Angular Package Format

npm npm License Conventional Commits CircleCI Travis

GitHub stars npm Downloads GitHub contributors GitHub issues GitHub pull requests

Renovate enabled David David David

Usage Example

For an Angular library, create one configuration file ng-package.json:

{
  "$schema": "./node_modules/ng-packagr/ng-package.schema.json",
  "lib": {
    "entryFile": "public_api.ts"
  }
}

Then, build the library from a npm/yarn script defined in package.json:

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

Now build with this command:

$ yarn build

Paths are resolved relative to the location of the ng-package.json file. The package.json describing the library should be located in the same folder, next to ng-package.json.

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: Supports dynamic discovery and bundling of secondary entry points
  • :mag_right: Creates either a scoped or a non-scoped packages for publishing to npm registry
  • :surfer: Inlines Templates and Stylesheets
  • :sparkles: CSS Features

Advanced Use Cases

Examples and Tutorials

Nikolas LeBlanc's story on medium.com: 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!

Configuration Locations

Configuration is picked up from the cli -p parameter, then from the default location for ng-package.json, then from package.json.

To configure with package.json, put your ng-package configuration in the ngPackage field:

{
  "$schema": "./node_modules/ng-packagr/package.schema.json",
  "ngPackage": {
    "lib": {
      "entryFile": "public_api.ts"
    }
  }
}

Note: the JSON $schema reference enables JSON editing support (autocompletion) for the custom ngPackage property in an IDE like VSCode.

Secondary Entry Points

Beside the primary entry point, a package can contain one or more secondary entry points (e.g. @angular/core/testing, @angular/cdk/a11y, …). These contain symbols that we don't want to group together with the symbols in the main entry. The module id of a secondary entry directs the module loader to a sub-directory by the secondary's name. For instance, @angular/core/testing resolves to a directory under node_modules/@angular/core/testing containing a package.json file that directs the loader to the correct location for what it's looking for.

For library developers, secondary entry points are dynamically discovered by searching for package.json files within sub directories of the main package.json file's folder!

So how do I use secondary entry points (sub-packages)?

All you have to do is create a package.json file and put it where you want a secondary entry point to be created. One way this can be done is by mimicking the folder structure of the following example which has a testing entry point in addition to its main entry point.

my_package
├── src
|   └── *.ts
├── public_api.ts
├── ng-package.json
├── package.json
├── testing
    ├── src
    |   └── *.ts
    ├── public_api.ts
    └── package.json

The contents of the secondary package.json can be as simple as:

{
  "ngPackage": {}
}

No, that is not a typo. No name is required. No version is required. It's all handled for you by ng-packagr! When built, the primary entry is imported with @my/library and the secondary entry with @my/library/testing.

What if I don't like public_api.ts?

You can change the entry point file by using the ngPackage configuration field in your secondary package.json. For example, the following would use index.ts as the secondary entry point:

{
  "ngPackage": {
    "lib": {
      "entryFile": "index.ts"
    }
  }
}
How do I use es2016 or es2017 features in my TypeScript library?

You can change the TypeScript language level support in tsconfig by also using the ngPackage configuration field in your secondary package.jsonand setting thelanguageLevelproperty inlib`: For example,:

{
  "ngPackage": {
    "lib": {
      "languageLevel": [ "dom", "es2017" ]
    }
  }
}
What if I want to use React Components?

If you have React Components that you're using in your library, and want to use proper JSX/TSX syntax in order to construct them, you can set the jsx flag for your library through ng-package like so:

{
  "$schema": "../../../src/ng-package.schema.json",
  "lib": {
    "entryFile": "public_api.ts",
    "externals": {
      "react": "React",
      "react-dom": "ReactDOM"
    },
    "jsx": "react"
  }
}

The jsx flag will accept anything that tsconfig accepts, more information here.

Note: Don't forget to include react and react-dom in your externals so that you're not bundling those dependencies.

Further 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.

Knowledge

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

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