【问题标题】:Angular2 app architecture (web, mobile, native)Angular2 应用架构(Web、移动、本机)
【发布时间】:2016-11-30 10:36:15
【问题描述】:

让我们想象一个处理以下平台的 ng2 应用:web、mobile-web 和 mobile-native。

由于有很多共享文件(redux 的东西,比如 action creators、reducers...、services、common components), 一切都可以在一个存储库中。在大多数情况下,组件和路由中的 web、mobile-web 和 mobile-native 视图登录之间存在差异。 一切都由 webpack 管理,它使用 .mobile.ts 和 .desktop.ts 扩展构建所有东西。具有 .base.ts 扩展名的文件包含桌面和移动组件之间的共享视图逻辑。

当前(简化)文件结构如下(桌面版是网页版,手机版是mobile-web):

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

但这似乎也很奇怪和不直观。

您对如何为这种情况制定更好的结构有什么建议吗?我将不胜感激任何帮助。感谢您的建议。

【问题讨论】:

  • 您是否尝试过根据您对项目结构的建议构建应用程序?如果有,你会推荐使用它吗?

标签: javascript angular redux single-page-application nativescript


【解决方案1】:

我建议你创建不同的项目并创建一个通用的角度包,如下所示:

  • common(包括 Angular 服务和助手)
  • 网络(组件和特定于网络的服务/视图)
  • mobile-web(组件和移动网络特定的服务/视图)
  • 移动原生(组件和原生特定服务/视图)

也许您可以同时加入网络和移动应用程序。但是这种设置在许多项目中都对我有用

【讨论】:

  • 您如何在这些项目之间共享资源?您是否将常用的东西复制到其他带有监视任务的项目中?我喜欢@Donut 发布的项目结构的想法,因为您不需要任何工作来共享资源
  • 您可以为共享组件创建单独的 NPM 包
猜你喜欢
  • 1970-01-01
  • 2014-05-06
  • 2011-08-11
  • 2015-01-04
  • 1970-01-01
  • 1970-01-01
  • 2016-08-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多