天天看点

SAP Spartacus Reference App Structurehttps://sap.github.io/spartacus-docs/reference-app-structure/

https://sap.github.io/spartacus-docs/reference-app-structure/

该概念在 SAP Spartacus 3.1 版本引入。

这个 Reference App Structure 是 SAP 推荐客户在搭建自己的 Spartacus Storefront 时所用的参考。

Spartacus 包含若干可以 lazy load 的 feature libraries.

SAP Spartacus Reference App Structurehttps://sap.github.io/spartacus-docs/reference-app-structure/

有一套标准的工程结构,也便于新开发人员进入项目后,快速熟悉项目并上手。

结构
SAP Spartacus Reference App Structurehttps://sap.github.io/spartacus-docs/reference-app-structure/
1. AppModule

SAP Spartacus Reference App Structurehttps://sap.github.io/spartacus-docs/reference-app-structure/

2. SpartacusModule
SAP Spartacus Reference App Structurehttps://sap.github.io/spartacus-docs/reference-app-structure/
3.BaseStorefrontModule
SAP Spartacus Reference App Structurehttps://sap.github.io/spartacus-docs/reference-app-structure/
从 @spartacus/storefront 里导入,再导出。

4.SpartacusFeatureModule

SAP Spartacus Reference App Structurehttps://sap.github.io/spartacus-docs/reference-app-structure/

5. feature related modules
SAP Spartacus Reference App Structurehttps://sap.github.io/spartacus-docs/reference-app-structure/
6. 配置 module

SAP Spartacus Reference App Structurehttps://sap.github.io/spartacus-docs/reference-app-structure/

每个 Angular 应用都有一个 root app module,通常命名为 AppModule. 在 SAP Spartacus reference app structure 里,AppModule 包含了应用层级的 imports:

SAP Spartacus Reference App Structurehttps://sap.github.io/spartacus-docs/reference-app-structure/

从上图可见,StoreModule 和 EffectsModule 等 module,因为整个应用的其他定制开发很可能也会用到,因此直接在 AppModule 里 import,而没有放到 SpartacusModule 里。

SpartacusModule 包含三部分:

SAP Spartacus Reference App Structurehttps://sap.github.io/spartacus-docs/reference-app-structure/

The BaseStorefrontModule, which encapsulates core Spartacus imports that are usually required by most Spartacus applications.

包含了任何 Spartacus 应用都必需的 imports.

SAP Spartacus Reference App Structurehttps://sap.github.io/spartacus-docs/reference-app-structure/
  1. The SpartacusFeaturesModule, which encapsulates Spartacus features.
    SAP Spartacus Reference App Structurehttps://sap.github.io/spartacus-docs/reference-app-structure/
    Spartacus feature 又分为两部分:来自 @Spartacus/storefront 和 features 文件夹下的 modules.

The SpartacusConfigurationModule, which encapsulates the general Spartacus configuration.

配置信息:

SAP Spartacus Reference App Structurehttps://sap.github.io/spartacus-docs/reference-app-structure/
SAP Spartacus Reference App Structurehttps://sap.github.io/spartacus-docs/reference-app-structure/

feature 相关的配置信息,推荐放到 feature modules 里,从而遵循关注点分离的原则。

继续阅读