Slide 1

Slide 1 text

No content

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

Creating Libraries in Angular Nishu Goel Developer, UI Garage, IBM Blog: https://nishugoel.wordpress.com/ Twitter: @Dcoustawilson

Slide 4

Slide 4 text

AGENDA ● Overview of Libraries ● Behind the scenes ● Creating a library and using it locally ● Importing your library in some Angular application ● Publishing your library to npm

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

Libraries? In programming, a collection of precompiled routines that a program can use.

Slide 7

Slide 7 text

In his talk, Create and publish Angular libs like a Pro , Juri Strumpflohner explains the need for a library with this image. Explains how our applications comprise of different javascript files and other external libraries and tools and how they are assembled together.

Slide 8

Slide 8 text

“Smallest set of logically connected code”

Slide 9

Slide 9 text

Button Library contains: Applications need: Button Button Button

Slide 10

Slide 10 text

A library should be:

Slide 11

Slide 11 text

• Module definitions • Typing files • Entry point • AOT ready metadata file

Slide 12

Slide 12 text

● Inlining all the templates ● Compiling it with ‘ngc’ ● Build formats: - ESM2015 (ES6) - ESM5 (combination of ES5 and imports, export from ES6) - UMD formats (combination of AMD and Common JS)

Slide 13

Slide 13 text

Creating all these is definitely a task! ng-packagr!

Slide 14

Slide 14 text

ng-packagr created by David Herges, allows libraries to be built and packaged using a single command ● Creates libraries in the Angular package format ● Creates all the bundles (ESM2015, ESM5, UMD) ● Creates type definitions (.d.ts) ● Creates Ahead-of-Time metadata file ● Also, inlines all the styles and templates!

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

Let’s create a library! ng generate library

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

Import and use in a separate application locally ● npm install – npm install ● npm link – npm link ● npm pack – npm pack

Slide 19

Slide 19 text

Publishing ● Login to npm ● Give a version and name (read about versioning here: https://semver.org) ● Publish with access flag ‘public’

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

https://github.com/NishuGoel/ngSLDemo

Slide 23

Slide 23 text

Some great resources to follow! ● angular.io/guide/using-libraries ● The Angular Library series: Angular In Depth ● Structuring Angular Applications with Angular libraries – Fabian Gosebrink ● ng-be 2017 talk Create and publish Angular libs like a Pro - Juri Strumpflohner

Slide 24

Slide 24 text

THANK YOU @Dcoustawilson NishuGoel