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

[Sebastian Witalec] Sharing Code Between Web an...

[Sebastian Witalec] Sharing Code Between Web and Native Apps

Presentation from GDG DevFest Ukraine 2017 - the biggest community-driven Google tech conference in the CEE.

Learn more at: https://devfest.gdg.org.ua

Google Developers Group Lviv

October 14, 2017
Tweet

More Decks by Google Developers Group Lviv

Other Decks in Technology

Transcript

  1. Sharing Code between 
 Web and Native apps You know

    Angular. Now you know mobile. @sebawita
  2. “The Web is for audience reach and native apps are

    for rich experiences. Both are strategic. Both are valuable. So when it comes to mobile, it's not Web vs. Native. It's both.” - Luke Wroblewski
  3. an open source framework for building truly native mobile apps

    with JavaScript. Use web skills, like TypeScript, Angular and CSS, and get native UI and performance on iOS and Android. NativeScript is…
  4. Project Structure Build tools UI app/code src/app/code NativeScript CLI Angular

    CLI Mobile Style Web Style Mobile Components Web components
  5. Approach 1: Multiple projects Shared Platform Agnostic Code Services Components

    Pipes SASS Variables Angular Web Project Angular {N} Project Shared Shared Web Code Mobile Code Copy Directives
  6. The Good The Bad The Ugly Easy Setup Good for

    small projects No learning curve Code Duplication Doesn't scale Maintenance
  7. Approach 2: Monorepo
 Monorepo Services Pipes SASS Variables Directives Web

    Style {N} Style Navigation Modules Components Web ngModule {N} ngModule Navigation Components Web HTML {N} HTML TS Class Build Process
  8. Approach 2: Monorepo
 Monorepo Services Pipes SASS Variables Directives Web

    Style Navigation Modules Components Web ngModule Navigation Components Web HTML TS Class Build Process {N} Style {N} ngModule {N} HTML
  9. Approach 2: Monorepo
 Monorepo Services Pipes SASS Variables Directives {N}

    Style Navigation Modules Components {N} ngModule Navigation Components {N} HTML TS Class Build Process Web Style Web ngModule Web HTML
  10. The Good The Bad The Ugly Angular CLI Great for

    complex project All in one place Overkill for small projects Needs additional build process How do I even start?
  11. Custom build How does it work?
 Mobile app Business as

    usual Monorepo angular-native-seed {N} Project Structure Web Project ng serve npm run android npm run ios
  12. How to do code splitting? Components Web HTML TS Class

    {N} HTML NameComponent name.component.html name.component.ts name.component.tns.html
  13. How to do code splitting? Components Web HTML TS Class

    {N} HTML NameComponent name.component.html name.component.ts name.component.tns.html Web Style {N} Style name.component.scss name.component.tns.scss
  14. Common Angular Data Service Interface Service Abstraction Web Plugin {N}

    Plugin Web Data Service Components Components Business Logic Web Data Service Business Logic
  15. Common Plugin Interface Higher Abstraction {N} Plugin Web Plugin Wrapper

    {N} Plugin Wrapper Components Components Data Service Business Logic Web Plugin
  16. Issue 1: Different user models uid name displayName email verifiedEmail

    refreshToken profileImageURL photoURL providers providerData anonumous isAnonymous
  17. nativescript-angular-cli > tns extension install nativescript-angular-cli > tns generate shared-component

    name > tns g sc name > tns generate shared-module name > tns g sm name