All Projects → robisim74 → Angular Library Starter

robisim74 / Angular Library Starter

Licence: other
Build an Angular library compatible with AoT compilation and Tree shaking like an official package

Programming Languages

javascript
184084 projects - #8 most used programming language
typescript
32286 projects

Projects that are alternatives of or similar to Angular Library Starter

Angular Library Seed
🌾 Seed project for Angular libraries that are AOT/JIT compatible and that use external SCSS-styles and HTML-templates
Stars: ✭ 197 (-27.57%)
Mutual labels:  library, aot-compilation
Egeo
EGEO is the open-source UI library used to build Stratio's UI. It includes UI Components, Utilities, Services and much more to build user interfaces quickly and with ease. The library is distributed in AoT mode.
Stars: ✭ 69 (-74.63%)
Mutual labels:  library, aot-compilation
Hypre
Parallel solvers for sparse linear systems featuring multigrid methods.
Stars: ✭ 260 (-4.41%)
Mutual labels:  library
Paper Switch
🎚 RAMPaperSwitch is a Swift material design UI module which paints over the parent view when the switch is turned on. iOS library by @Ramotion
Stars: ✭ 2,902 (+966.91%)
Mutual labels:  library
Landscapist
🍂 Jetpack Compose image loading library which can fetch and display network images using Glide, Coil, and Fresco.
Stars: ✭ 264 (-2.94%)
Mutual labels:  library
Rapidcsv
C++ CSV parser library
Stars: ✭ 261 (-4.04%)
Mutual labels:  library
Cordova Plugin Dialogs
Apache Cordova Plugin dialogs
Stars: ✭ 267 (-1.84%)
Mutual labels:  library
Ui Neumorphism
📕 React component library designed on the "new skeuomorphism" or "neumorphism" UI/UX trend.
Stars: ✭ 258 (-5.15%)
Mutual labels:  library
Cordova Plugin Media Capture
Apache Cordova Plugin media-capture
Stars: ✭ 271 (-0.37%)
Mutual labels:  library
Prdownloader
PRDownloader - A file downloader library for Android with pause and resume support
Stars: ✭ 2,947 (+983.46%)
Mutual labels:  library
Visitor
The Hoa\Visitor library.
Stars: ✭ 269 (-1.1%)
Mutual labels:  library
Ristretto
A high performance memory-bound Go cache
Stars: ✭ 3,584 (+1217.65%)
Mutual labels:  library
Public Transport Enabler
Unleash public transport data in your Java project.
Stars: ✭ 264 (-2.94%)
Mutual labels:  library
I Use Arch Btw
"I use Arch btw" but it's a Turing-complete programming language.
Stars: ✭ 266 (-2.21%)
Mutual labels:  library
Node Window Manager
Manage windows in Windows, macOS and Linux using Node.js
Stars: ✭ 263 (-3.31%)
Mutual labels:  library
Gorequest
GoRequest -- Simplified HTTP client ( inspired by nodejs SuperAgent )
Stars: ✭ 3,063 (+1026.1%)
Mutual labels:  library
Incrementproductview
Interesting concept of products incrementation
Stars: ✭ 262 (-3.68%)
Mutual labels:  library
Pygogo
A Python logging library with superpowers
Stars: ✭ 265 (-2.57%)
Mutual labels:  library
Bottomsheet Imagepicker
Modern image picker for Android
Stars: ✭ 267 (-1.84%)
Mutual labels:  library
Rye
A modern, lightweight browser library using ES5 natives
Stars: ✭ 271 (-0.37%)
Mutual labels:  library

angular-library-starter

Build Status

Build an Angular library compatible with AoT compilation & Tree shaking like an official package.

This starter allows you to create a library for Angular apps. The project is based on the official Angular packages.

Get the Changelog.

Contents

1 Project structure

  • Library:
    • src folder for the classes
    • public_api.ts entry point for all public APIs of the package
    • package.json npm options
    • rollup.config.js Rollup configuration for building the umd bundles
    • rollup.es.config.js Rollup configuration for building the es2015 bundles
    • tsconfig-build.json ngc compiler options for AoT compilation
    • build.js building process using ShellJS
  • Testing:
    • tests folder for unit & integration tests
    • karma.conf.js Karma configuration that uses webpack to build the tests
    • spec.bundle.js defines the files used by webpack
  • Extra:
    • tslint.json Angular TSLint Preset (TypeScript linter rules with Codelyzer)
    • travis.yml Travis CI configuration

2 Customizing

  1. Update Node & npm.

  2. Rename angular-library-starter and angularLibraryStarter everywhere to my-library and myLibrary.

  3. Customize the license-banner.txt file with your library license.

  4. Update in package.json file:

    • version: Semantic Versioning
    • description
    • urls
    • packages (optional): make sure you use a version of TypeScript compatible with Angular Compiler

    and run npm install.

  5. Create your classes in src folder, and export public classes in my-library.ts.

  6. You can create only one module for the whole library: I suggest you create different modules for different functions, so that the host app can only import the modules it uses, and optimize its Tree shaking.

  7. Update in rollup.config.js file globals external dependencies with those that actually you use to build the umd bundle.

  8. Create unit & integration tests in tests folder, or unit tests next to the things they test in src folder, always using .spec.ts extension.

3 Testing

The following command runs unit & integration tests that are in the tests folder (you can change the folder in spec.bundle.js file):

npm test 

or in watch mode:

npm run test:watch

It also reports coverage using Istanbul.

4 Building

The following command:

npm run build
  • starts TSLint with Codelyzer using Angular TSLint Preset
  • starts AoT compilation using ngc compiler
  • creates dist folder with all the files of distribution, following Angular Package Format (APF):
└── dist
    ├── bundles
    |   ├── my-library.umd.js
    |   ├── my-library.umd.js.map
    |   ├── my-library.umd.min.js
    |   └── my-library.umd.min.js.map
    ├── esm5
    |   ├── **/*.js
    |   └── **/*.js.map
    ├── esm2015
    |   ├── **/*.js
    |   └── **/*.js.map
    ├── fesm5
    |   ├── my-library.js
    |   └── my-library.js.map
    ├── fesm2015
    |   ├── my-library.js
    |   └── my-library.js.map
    ├── src
    |   └── **/*.d.ts
    ├── my-library.d.ts
    ├── my-library.metadata.json
    ├── LICENSE
    ├── package.json
    ├── public_api.d.ts
    └── README

To test locally the npm package before publishing:

npm run pack:lib

Then you can install it in an app to test it:

npm install [path]my-library-{version}.tgz

5 Publishing

Before publishing the first time:

npm run publish:lib

6 Documentation

To generate the documentation, this starter uses compodoc:

npm run compodoc
npm run compodoc:serve 

7 Using the library

Installing

npm install my-library --save 

Loading

Angular-CLI

No need to set up anything, just import it in your code.

Rollup or webpack

No need to set up anything, just import it in your code.

Using SystemJS configuration

System.config({
    map: {
        'my-library': 'node_modules/my-library/bundles/my-library.umd.js'
    }
});

Plain JavaScript

Include the umd bundle in your index.html:

<script src="node_modules/my-library/bundles/my-library.umd.js"></script>

and use global ng.myLibrary namespace.

AoT compilation

The library is compatible with AoT & Ivy.

8 What it is important to know

  1. package.json

    • "main": "./bundles/angular-library-starter.umd.js" legacy module format
    • "module": "./esm5/angular-library-starter.js" flat ES module, for using module bundlers such as Rollup or webpack
    • "es2015": "./esm2015/angular-library-starter.js" ES2015 flat ESM format
    • "typings" declaration files for TypeScript compiler
    • "peerDependencies" the packages and their versions required by the library when it will be installed
  2. tsconfig.json file used by TypeScript compiler

    • Compiler options:
      • "strict": true enables TypeScript strict master option
  3. tsconfig-build.json file used by ngc compiler

    • Compiler options:

      • "declaration": true to emit TypeScript declaration files
      • "module": "es2015" & "target": "es2015" are used by Rollup to create the ES2015 bundle
    • Angular Compiler Options:

      • "enableResourceInlining": true inlining of templates & styles
      • "skipTemplateCodegen": true skips generating AoT files
      • "strictMetadataEmit": true without emitting metadata files, the library will not be compatible with AoT compilation: it is intended to report syntax errors immediately rather than produce a .metadata.json file with errors
      • "flatModuleId": "@scope/package" full package name has to include scope as well, otherwise AOT compilation will fail in the consumed application
      • "enableIvy": false libraries don't need to enable Ivy
  4. rollup.config.js file used by Rollup

    • format: 'umd' the Universal Module Definition pattern is used by Angular for its bundles
    • moduleName: 'ng.angularLibraryStarter' defines the global namespace used by JavaScript apps
    • external & globals declare the external packages
  5. Server Side Rendering

    If you want the library will be compatible with Server Side Rendering:

    • window, document, navigator and other browser types do not exist on the server
    • don't manipulate the nativeElement directly

9 Inlining of templates and stylesheets

Now ngc compiler supports inlining of templates & styles. Moreover, this starter allows you to use .scss sass files. If you need, you can use different pre-processors.

Built with this starter

  • angular-auth-oidc-client An OpenID Connect Implicit Flow client for Angular
  • ngx-infinite-scroll An infinite scroll directive for Angular compatible with AoT compilation and Tree shaking
  • ngx-typeahead A simple but yet powerful typeahead component for Angular
  • ng2-youtube-player A Powerful Youtube Player Component for Angular
  • ng2-completer Angular autocomplete component
  • ngx-store Angular Storage library for managing localStorage, sessionStorage and cookies, allowing to watch storage changes. Includes easy-to-use decorators, services and API based on builder pattern.
  • ngx-table-editor A library for Angular that transforms HTML tables into dynamic editable components.
  • ngx-ui-scroll An Angular *ngFor-like directive for infinite/virtual scrolling

Previous versions

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].