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

Angular im Enterprise-Umfeld

Angular im Enterprise-Umfeld

Session von w-jax 2017, München

Manfred Steyer

November 08, 2017
Tweet

More Decks by Manfred Steyer

Other Decks in Programming

Transcript

  1. Über mich … • Manfred Steyer • SOFTWAREarchitekt.at • Trainer

    & Consultant • Fokus: Angular • Google Developer Expert (GDE) Page ▪ 2 Manfred Steyer
  2. Inhalt • Modulstruktur und Lazy Loading • Wiederverwendbare Bibliotheken •

    State Mangement und Redux (ngrx) • Internationalisierung • [Login, 16:15, Raum München]
  3. Modul Struktur Page ▪ 6 AppModule … … … SharedModule

    Root Module Feature Modules Shared Module
  4. Lazy Loading Page ▪ 7 AppModule … … … SharedModule

    Root Module Feature Modules Shared Module
  5. Root Module mit Lazy Loading Page ▪ 8 const APP_ROUTE_CONFIG:

    Routes = [ { path: 'home', component: HomeComponent }, { path: 'flights', loadChildren: './[…]flight-booking.module#FlightBookingModule' } ];
  6. Routen für lazy Modules Page ▪ 9 const FLIGHT_ROUTES =

    [ { path: '', component: FlightBookingComponent, […] }, […] }
  7. Idee • Modul nach Start der Anwendung lazy laden •

    Wenn Modul später benötigt wird, steht es sofort zur verfügung Page ▪ 12
  8. Idee hinter Barrels • ES Module: Datei == Modul •

    Viel zu feingranular für Konsument einer API • Barrel == Façade für Module == Public API
  9. index.ts as Barrel export * from './src/demo.service'; export { OtherDemoService

    } from './src/other-demo.service'; @NgModule({ … }) export class LibStarterModule { }
  10. Generator • npm install -g yo • npm install -g

    generator-angular2-library • yo angular2-library
  11. Lessons Learned • Debugging: Link src folder • Oder: src

    kopieren • ng serve --preserve-symlinks • Vor Produktion: Ordner dist linken und mit Angular Compiler (AOT) testen
  12. Veröffentlichen • Version in package.json erhöhen • npm version [patch

    | minor | major | version] • npm run build • cd ../dist • npm publish --registry http://localhost:4873 • npm install --registry http://localhost:4873
  13. Lokale npm-Registry • TFS • Nexus • Verdaccio • Very

    lightweight • npm i -g verdaccio • Start: verdaccio
  14. Alternativen zum Festlegen der Registry • Global: npm set registry

    http://localhost:4873 • Standard: registry.npmjs.org • npm get registry • Projekt: .npmrc in project root
  15. App Home Booking Boarding Store State … boarding statistics bookings

    Boarding Reducer State State State Action Action Action Action … Reducer Action Single Immutable State Tree … Redux für Angular
  16. Angular Compiler • Extrahiert Texte aus Templates in Sprachfiles •

    Formate • XML Message Bundle (XMB) • XML Localisation Interchange File Format (XLIFF, version 1.2) • Kompiliert Sprachfiles zurück in Anwendung • Kompilierung beim Start (JIT) oder Build (AOT) • https://angular.io/docs/ts/latest/cookbook/i18n.html • Sprache kann im Betrieb nicht geändert werden (aber: Work in Progress) • Hohe Performance • Wird laufend erweitert Page ▪ 40
  17. Angular Translate • Community Lösung • Leichtgewichtig, erweiterbar • https://github.com/ngx-translate

    • Migration von defacto-Standard für AngularJS 1.x • JSON-basierte Dateien • Sprache kann während der Laufzeit geändert werden • Nicht so performant wie Angular Compiler I18N • Keine (offizielle) Möglichkeit, Texte zu extrahieren Page ▪ 41
  18. Build Optimizer • Build Optimizer macht Code besser "treeshakable" •

    Standard für Production Builds seit Angular CLI 1.5
  19. Zusammenfassung Module Lazy Loading & Preloading Pakete Angular Package Format

    & Generator State Management und Redux I18N mit Compiler oder ngx-translate Production Build Build Optimizer & Co.