2

讓我們想象一個處理以下平臺的ng2應用程序:web,mobile-web和mobile-native。Angular2應用程序體系結構(網頁,手機,原生)

由於事實上有很多共享文件(比如動作創建者,reducer ...,服務,通用組件), 所有內容都可以放在一個存儲庫中。在大多數情況下,組件和路由中的web,移動web和移動原生視圖登錄存在差異。 一切都由webpack管理,它使用.mobile.ts和.desktop.ts擴展來構建所有的東西。帶有.base.ts擴展名的文件包含桌面和移動組件之間的共享視圖邏輯。

電流(簡體)文件結構如下(桌面網頁版,手機是移動網絡):

assets/ 
app/ 
    /common 
     actions/ 
     enums/ 
     models/ 
     effects/ 
     pipes/ 
     reducers/ 
     services/ 
     components/ 
      account-list/ 
       account-item/ 
        account-item.component.base.ts 
        account-item.component.desktop.ts 
        account-item.component.desktop.html 
        account-item.component.mobile.ts 
        account-item.component.mobile.html 
        index.ts 
       account-list.component.base.ts 
       account-list.component.desktop.ts 
       account-list.component.desktop.html 
       account-list.component.mobile.ts 
       account-list.component.mobile.html 
       index.ts 
    /modules 
     /desktop 
      /accounts 
       accounts.component.desktop.ts 
       accounts.component.desktop.html 
       accounts.routes.desktop.ts 
       index.ts 
     /mobile 
      /accounts 
       accounts.component.mobile.ts 
       accounts.component.mobile.html 
       accounts.routes.mobile.ts 
       index.ts 
    app.component.desktop.ts 
    app.component.mobile.ts 
    app.module.desktop.ts 
    app.module.mobile.ts 
    app.routes.desktop.ts 
    app.routes.mobile.ts 

正如你可以看到,文件的數量增長如此之快。我害怕通過添加另一個本地平臺來考慮它的外觀。不幸的是,我無法找到任何有趣的案例。

,我已經找到了只有一個: Angular2 advanced seed link

但似乎preety怪異和不直觀的爲好。

對於這種情況,你有什麼建議如何使結構更好?我會很感激任何幫助。謝謝你的建議。

+0

您是否嘗試過使用您對項目結構的建議來構建應用程序?如果是這樣,你會推薦使用它嗎? – Weissvonnix

回答

0

我會建議你創建不同的項目,並創建一個相同的角度包,就像這樣:

  • 共同(包括角服務和傭工)
  • 網絡(成分和特定網頁服務/視圖)
  • mobile-web(組件和移動web特定服務/視圖)
  • mobile-native(組件和原生特定服務/視圖)

也許你可以一起加入web和移動應用程序。但是這個設置在很多項目中都適用於我

+0

你如何分享這些項目之間的資源?您是否將通用內容複製到其他具有監視任務的項目中?我喜歡@Donut發佈的項目結構的想法,因爲您不需要任何作業來共享資源 – Weissvonnix

+0

您可以爲共享組件創建單獨的NPM軟件包 – hypery2k