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

ng-lib-schematics

v0.3.0

Published

Angular schematics to easily create Angular libraries

Downloads

11

Readme

Angular Library Schematics

Create Angular libraries in no time using Schematics. Think of ng generate component, but for libraries.

Features

  • Easily generate libraries from scratch or within your existing Angular project.
  • Release a build that follows Angular standards: UMD, ES5 and ES2015 bundles + typings.
  • Seemless integration with Angular CLI. Your library playground will just be your well known Angular app.
  • Test your library using karma + jasmine as you normally do in your Angular apps
  • Support for dry run
  • SASS and autoprefixer support.

Installation

  1. It's recommended to install the schematics globally because you'll likely use it to create projects from scratch where no node_modules is yet available.
npm i -g ng-lib-schematics
  1. Make sure you have the Angular DevKit dependencies to run the schematics:
npm i -g @angular-devkit/core @angular-devkit/schematics-cli

Basic Usage

This schematic will generate the library inside of an existing Angular project. If you already have a project in which you want to include your library then you can skip step 1.

  1. Create an Angular project using the CLI. It's recommendable to skip install now to run npm i only once at step 3.
ng new <library-name> --skip-install
  1. cd into your new project and run the schematics inside:
schematics ng-lib-schematics:lib-standalone --name <library-name>
  1. Install dependencies
npm i
  1. Import your library module inside app.module.ts. Your library is now just another module of your app:
import { SampleModule } from '../lib';
...
imports: [ BrowserModule, SampleModule ]
  1. Start using it! Go to your app.component.html and add the sample component:<sample-component></sample-component>. It should render this:

Note: Make sure you run the schematics in dry run mode first to know upfront what this thing will do to your project. Once you get comfortable with all the changes you can run the schematics again without dry run. To dry run the schematic simply append the --dry-run flag to the command in step 2.

Building and publishing your library

  1. npm run build:lib
  2. cd dist
  3. npm publish

Important:

  1. If you already have an npm script named build:lib in your project, then you'll have to manually run gulp --gulpfile gulpfile.lib.js to build the library.
  2. TODO sync version

Generated files

It's important that you know what this schematic will do and how your project will look like after applying it:

  1. The library will live inside src/lib.
  2. All your components, services, directives, etc will live inside the folder src/lib/src. You can safely change the names of the existing files inside this folder and go nuts building your library.
  3. The build script will live inside src/lib/build-tools along with all the build utils.
  4. A file gulpfile.lib.js will be created at the root of the project. It will simple import the main gulpfile located at src/lib/src/build-tools/gulpfile.js.
  5. New dependencies will be added to your devDependencies. These are needed to build your library at the release stage.
  6. Two npm scripts will be added to thet scripts object inside your main package.json file: a. "build:lib": "gulp --gulpfile gulpfile.lib.js": Script to build the release artifacts of your library. b. "version": "sync-json -v --property version --source package.json src/lib/package.json": Version hook to sync versions between your root package.json and src/lib/package.json. This will allow you to run npm version <type> at the root of your project and still have your library version up to date.

Contributing

Thanks for even thinking about contributing. Open up issues or PRs and we'll discuss about it.

Testing your schematics build

  1. Fork the project
  2. Install dependencies npm i
  3. Run npm run watch. This will output the schematic package to dist and watch for changes.
  4. cd into dist and run npm link. At this point, ng-lib-schematics is symlinked to your global node_modules.
  5. Create a dummy Angular project ng new lib-test
  6. You can now run schematics ng-lib-schematics:lib-standalone --name <library-name>

Hall of fame

Find below some of the libraries built on top of these schematics:

  • Nothing here yet. Open a PR and shoot your library right here!

Credits

I took a bunch of ideas from the Yeoman's Angular library generator by Jurgen Van de Moere. Feel free to use whatever works best for you, both Schematics and Yeoman will get you to the same exact point.

Licence

MIT