# ngmakelib

> Command line tool for building Angular libraries

Latest version **0.2.6** (published 2018-10-03) · 0 weekly downloads

## Install

```sh
npm install ngmakelib
pnpm add ngmakelib
yarn add ngmakelib
bun add ngmakelib
```

Provides the command `ngmakelib`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.6 |
| Published | 2018-10-03 |
| First published | 2018-01-15 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 38.4 KB |
| Known vulnerabilities | 0 (+4 in 2 direct dependencies) |
| Install scripts | no |
| Maintainers | petersalomonsen |

## Links

- npm: https://www.npmjs.com/package/ngmakelib
- Homepage: https://github.com/fintechneo/ngmakelib
- Issues: https://github.com/fintechneo/ngmakelib/issues
- npm.io page: https://npm.io/package/ngmakelib

## Dependencies (5)

- [cpx](https://npm.io/package/cpx.md)
- [rollup](https://npm.io/package/rollup.md) ^0.50.0
- [shelljs](https://npm.io/package/shelljs.md) ^0.7.8
- [node-sass](https://npm.io/package/node-sass.md)
- [@angular/compiler-cli](https://npm.io/package/@angular/compiler-cli.md)

## Recent versions

- 0.2.6 (latest) — 2018-10-03
- 0.2.5 — 2018-06-21
- 0.2.4 — 2018-04-26
- 0.2.3 — 2018-04-05
- 0.2.2 — 2018-04-05
- 0.2.1 — 2018-03-26
- 0.2.0 — 2018-03-09
- 0.1.3 — 2018-03-01
- 0.1.2 — 2018-03-01
- 0.1.1 — 2018-03-01
- 0.1.0 — 2018-03-01
- 0.0.1 — 2018-01-15

## README

# ngmakelib
NPM command line tool for generating Angular libraries

```
npm install ngmakelib
```

To create the library run:

```
./node_modules/.bin/ngmakelib src/app/mymodule/mymodule.module.ts mymodule-library 0.1.1
```

And if all goes well you will have a file called ``mymodule-library-0.1.1.tar.gz``

Finally to install the library in another Angular project type:

```
npm install file:path/to/mymodule-library-0.1.1.tar.gz
```

## API to get more control of the build process

If you need to control typescript (ngc) or rollup configuration options you may use the API. E.g. if you want to use the moment library with @angular/material you need to set the allowSyntheticDefaultImports option
in tsconfig.json to true.

Here's a simple script that set this option and build a library using the NGMakeLib API. 

```
var NGMakeLib = require('ngmakelib').NGMakeLib;

// Initialize NGMakeLib with entry point source file and module name
var ngMakeLib = new NGMakeLib('src/app/mymodule/mymodule.module.ts', 'my-module-library');

// Add the allowSyntheticDefaultImports to support 'moment'
ngMakeLib.ngcConfig.compilerOptions.allowSyntheticDefaultImports = true;

// Create the library
ngMakeLib.build().then(function() { console.log("All done"); });
```
## Watch mode during development

```
./node_modules/.bin/ngmakelib --watch src/app/mymodule/mymodule.module.ts mymodule-library 0.1.1
```

And then you can link the `.ngmakelibtmp/build` folder to any project where you want to test consuming the library.

### Note when linking from an @angular/cli host app

In `angular-cli.json` under `defaults -> build` you should set the `preserveSymlinks` to true like this:

```
"defaults": {
   "build": {
      "preserveSymlinks": true
    }
}
```
this prevents the linked library from using it's own `node_modules` folder for resolving dependencies - which can cause unwanted effects when using linked mode.

## Adding assets

If you need to include assets like images, other js script files, webassembly binaries etc, ngmakelib supports adding these to the assets folder of the exported library.

When consuming a library in assets in Angular CLI, you need to add the following to your `angular-cli.json`:

```
    "assets": [
      "assets",
      "favicon.ico",
      { "glob": "**/*", "input": "../node_modules/my-library/assets/", "output": "./assets/" }        
    ],
```
Replace `my-library` with the name of your library.

For adding assets with ngmakelib you will use the `addAssets` method of the ngmakelib api.

Here's an example script for building a library with assets (taken from the angular-git-filebrowser project https://github.com/fintechneo/angular-git-filebrowser):

```
var NGMakeLib = require('ngmakelib').NGMakeLib;

// Initialize NGMakeLib with entry point source file and module name
var ngMakeLib = new NGMakeLib('src/lib/filebrowser.module.ts', 'angular-filebrowser');

// Add assets
ngMakeLib.addAssets([
        'stupid_worker.js',
        'libgit2.js',
        'libgit2.wasm'
    ].map(a => 'src/assets/' +a)
);


if(process.argv[process.argv.length-1] === '--watch') {
    // Create the library and watch for changes
    ngMakeLib.watch();
} else {
    // Build package that can be published
    ngMakeLib.build();
}
```

## Developing ngmakelib

The development environment is set up with mocha test suites that you can run by typing:

`npm run test`

You'll find the sources for these in the `test` folder.

Also there's is the `examplelibrary_src` folder that is used in the test suites. This contains an example source for a library.

---
_Source: https://npm.io/package/ngmakelib · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
