Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Angular Architekturen with Angular Libraries

Angular Architekturen with Angular Libraries

Angular offers many possibilities when it comes to the separation and architecture of your application. There is often code that you not only want to reuse within your application, but also make available to other applications in your organization or via package managers such as npm over the Internet. This is where Angular's libraries come in.

In this talk, Fabian Gosebrink will explain how Angular Libraries are created, what the Angular Package format is good for, and how we can move code from an existing application to an Angular Library for reuse across multiple applications. This makes the maintainability and architecture of Angular applications easy.

Fabian Gosebrink

October 15, 2019
Tweet

More Decks by Fabian Gosebrink

Other Decks in Technology

Transcript

  1. View Slide

  2. View Slide

  3. View Slide

  4. View Slide

  5. View Slide

  6. View Slide

  7. View Slide

  8. View Slide

  9. View Slide

  10. View Slide

  11. View Slide

  12. View Slide

  13. View Slide

  14. View Slide

  15. View Slide

  16. View Slide

  17. View Slide

  18. View Slide

  19. View Slide

  20. View Slide

  21. View Slide

  22. View Slide

  23. View Slide

  24. View Slide

  25. View Slide

  26. View Slide

  27. View Slide

  28. View Slide

  29. View Slide

  30. View Slide

  31. View Slide

  32. View Slide

  33. View Slide

  34. View Slide

  35. View Slide

  36. View Slide

  37. View Slide

  38. View Slide

  39. View Slide

  40. View Slide

  41. View Slide

  42. public-api.ts
    *.ts
    package.json

    View Slide

  43. public-api.ts
    *.ts
    package.json

    View Slide

  44. public-api.ts
    *.ts
    package.json
    *.d.ts
    package.json
    bundles
    esm5
    esm2015

    View Slide

  45. View Slide

  46. View Slide

  47. View Slide

  48. View Slide

  49. View Slide

  50. NgModule({
    declarations: [MyComponent]
    })
    export class XyzModule
    MyComponent

    View Slide

  51. import { XyzModule } from ‘folder’;
    @NgModule({
    imports: [
    XyzModule
    ]})
    export class AppModule {}
    NgModule({
    declarations: [MyComponent]
    })
    export class XyzModule
    MyComponent

    View Slide

  52. MyComponent
    import { XyzModule } from ‘folder’;
    @NgModule({
    imports: [
    XyzModule
    ]})
    export class AppModule {}
    NgModule({
    declarations: [MyComponent]
    })
    export class XyzModule
    MyComponent

    View Slide

  53. MyComponent
    import { XyzModule } from ‘folder’;
    @NgModule({
    imports: [
    XyzModule
    ]})
    export class AppModule {}
    NgModule({
    declarations: [MyComponent]
    })
    export class XyzModule
    MyComponent

    View Slide

  54. MyComponent
    import { XyzModule } from ‘folder’;
    @NgModule({
    imports: [
    XyzModule
    ]})
    export class AppModule {}
    NgModule({
    declarations: [MyComponent],
    exports: [MyComponent]
    })
    export class XyzModule
    MyComponent

    View Slide

  55. @NgModule({
    imports: [
    ]})
    export class AppModule {}
    NgModule({
    declarations: [MyComponent],
    exports: [MyComponent]
    })
    export class XyzModule
    MyComponent

    View Slide

  56. import { XyzModule } from ‘lib’
    @NgModule({
    imports: [
    XyzModule
    ]})
    export class AppModule {}
    NgModule({
    declarations: [MyComponent],
    exports: [MyComponent]
    })
    export class XyzModule
    MyComponent

    View Slide

  57. import { XyzModule } from ‘lib’
    @NgModule({
    imports: [
    XyzModule
    ]})
    export class AppModule {}
    NgModule({
    declarations: [MyComponent],
    exports: [MyComponent]
    })
    export class XyzModule
    MyComponent
    export * from ‘./xyz.module’
    public-api.ts

    View Slide

  58. import { XyzModule } from ‘lib’
    @NgModule({
    imports: [
    XyzModule
    ]})
    export class AppModule {}
    NgModule({
    declarations: [MyComponent],
    exports: [MyComponent]
    })
    export class XyzModule
    MyComponent
    export * from ‘./xyz.module’
    public-api.ts
    MyComponent

    View Slide

  59. import { XyzModule, MyComponent }
    from ‘lib’
    @NgModule({
    imports: [
    XyzModule
    ]})
    export class AppModule {}
    NgModule({
    declarations: [MyComponent],
    exports: [MyComponent]
    })
    export class XyzModule
    MyComponent
    export * from ‘./xyz.module’
    public-api.ts
    MyComponent

    View Slide

  60. import { XyzModule, MyComponent }
    from ‘lib’
    @NgModule({
    imports: [
    XyzModule
    ]})
    export class AppModule {}
    NgModule({
    declarations: [MyComponent],
    exports: [MyComponent]
    })
    export class XyzModule
    MyComponent
    export * from ‘./xyz.module’
    public-api.ts
    MyComponent

    View Slide

  61. import { XyzModule, MyComponent }
    from ‘lib’
    @NgModule({
    imports: [
    XyzModule
    ]})
    export class AppModule {}
    NgModule({
    declarations: [MyComponent],
    exports: [MyComponent]
    })
    export class XyzModule
    MyComponent
    export * from ‘./xyz.module’
    export * from ‘my.component’
    public-api.ts
    MyComponent

    View Slide

  62. NgModule({
    providers: [MyService]
    })
    export class XyzModule
    MyService

    View Slide

  63. NgModule({
    providers: [MyService]
    })
    export class XyzModule
    MyService
    export * from ‘./xyz.module’
    public-api.ts

    View Slide

  64. NgModule({
    providers: [MyService]
    })
    export class XyzModule
    MyService
    export * from ‘./xyz.module’
    public-api.ts
    import { XyzModule } from ‘lib’
    @NgModule({
    imports: [
    XyzModule
    ]})
    export class AppModule {}

    View Slide

  65. NgModule({
    providers: [MyService]
    })
    export class XyzModule
    MyService
    export * from ‘./xyz.module’
    public-api.ts
    import { XyzModule } from ‘lib’
    @NgModule({
    imports: [
    XyzModule
    ]})
    export class AppModule {}
    import { MyService } from ‘lib’;
    constructor(private srv: MyService) {}

    View Slide

  66. NgModule({
    providers: [MyService]
    })
    export class XyzModule
    MyService
    export * from ‘./xyz.module’
    export * from ‘./my.service’
    public-api.ts
    import { XyzModule } from ‘lib’
    @NgModule({
    imports: [
    XyzModule
    ]})
    export class AppModule {}
    import { MyService } from ‘lib’;
    constructor(private srv: MyService) {}

    View Slide

  67. NgModule({
    providers: []
    })
    export class XyzModule
    @Injectable({ providedIn: ‘root’ })
    MyService
    export * from ‘./xyz.module’
    public-api.ts
    @NgModule({
    imports: [
    ]})
    export class AppModule {}

    View Slide

  68. NgModule({
    providers: []
    })
    export class XyzModule
    @Injectable({ providedIn: ‘root’ })
    MyService
    export * from ‘./xyz.module’
    public-api.ts
    @NgModule({
    imports: [
    ]})
    export class AppModule {}
    import { MyService } from ‘lib’;
    constructor(private srv: MyService) {}

    View Slide

  69. NgModule({
    providers: []
    })
    export class XyzModule
    @Injectable({ providedIn: ‘root’ })
    MyService
    export * from ‘./xyz.module’
    export * from ‘./my.service’
    public-api.ts
    @NgModule({
    imports: [
    ]})
    export class AppModule {}
    import { MyService } from ‘lib’;
    constructor(private srv: MyService) {}

    View Slide

  70. View Slide

  71. $ ng generate library my-lib

    View Slide

  72. View Slide

  73. $ ng build my-lib

    View Slide

  74. $ ng build my-lib --watch

    View Slide

  75. View Slide

  76. View Slide

  77. $ ng lint my-lib

    View Slide

  78. $ ng test my-lib

    View Slide

  79. $ ng test my-lib –-watch=false

    View Slide

  80. View Slide

  81. View Slide

  82. $ npm install my-lib/dist

    View Slide

  83. $ npm link my-lib/dist

    View Slide

  84. $ cd my-lib/dist
    $ npm pack
    $ npm install my-lib/dist/package.tgz

    View Slide

  85. View Slide

  86. View Slide

  87. View Slide

  88. {
    "name": "angular-rating",
    "version": "0.0.1",
    "peerDependencies": {
    "@angular/common": "^6.0.0-rc.0 || ^6.0.0",
    "@angular/core": "^6.0.0-rc.0 || ^6.0.0"
    }
    }

    View Slide

  89. {
    "name": "angular-rating",
    "version": "0.0.1",
    "peerDependencies": {
    "@angular/common": "^6.0.0-rc.0 || ^6.0.0",
    "@angular/core": "^6.0.0-rc.0 || ^6.0.0"
    }
    }

    View Slide

  90. ..
    https://semver.org/

    View Slide

  91. View Slide

  92. $ npm version patch

    View Slide

  93. $ npm version minor

    View Slide

  94. $ npm version major

    View Slide

  95. {
    "name": "angular-rating",
    "version": "0.0.1",
    "peerDependencies": {
    "@angular/common": "^6.0.0-rc.0 || ^6.0.0",
    "@angular/core": "^6.0.0-rc.0 || ^6.0.0"
    }
    }

    View Slide

  96. {
    "name": "@fabiangosebrink/angular-rating",
    "version": "0.0.1",
    "peerDependencies": {
    "@angular/common": "^6.0.0-rc.0 || ^6.0.0",
    "@angular/core": "^6.0.0-rc.0 || ^6.0.0"
    }
    }

    View Slide

  97. View Slide

  98. View Slide

  99. View Slide

  100. View Slide

  101. View Slide

  102. View Slide

  103. View Slide

  104. View Slide

  105. View Slide