关于spa:SAP-Spartacus-Reference-App-Structure

77次阅读

共计 2107 个字符,预计需要花费 6 分钟才能阅读完成。

https://sap.github.io/spartac…

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

这个 Reference App Structure 是 SAP 举荐客户在搭建本人的 Spartacus Storefront 时所用的参考。

Spartacus 蕴含若干能够 lazy load 的 feature libraries.

Customizations and third-party code add further complexity, and you can end up with modules that are difficult to maintain because they mix too many of these elements together.

定制化和第三方代码进一步减少了我的项目复杂度,如果解决不得当,很容易呈现堆砌了大量 module,难于保护的状况。

This can be solved by defining and adhering to a standardized structure, such as the Spartacus reference app structure.

而遵循 Spartacus reference app structure 来开发,就能防止此类问题呈现。

Having a standardized structure also makes it easier to onboard new developers to your project, to handle external support cases, and to take care of audits.

有一套规范的工程构造,也便于新开发人员进入我的项目后,疾速相熟我的项目并上手。

构造

1. AppModule

2. SpartacusModule

3.BaseStorefrontModule

从 @spartacus/storefront 里导入,再导出。

4.SpartacusFeatureModule

5. feature related modules

6. 配置 module

Every Angular application has a root app module, usually named AppModule. In the reference app strcuture, this module includes application-wide imports, and avoids complex module imports related to Spartacus by handling only one SpartacusModule.

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

Both Angular Router and NgRx are used by Spartacus, but these affect the global application, so they are kept outside of the SpartacusModule and are imported directly in the AppModule.

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

SpartacusModule 蕴含三局部:

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

蕴含了任何 Spartacus 利用都必须的 imports.

The BaseStorefrontModule is imported directly from @spartacus/storefront.

  1. The SpartacusFeaturesModule, which encapsulates Spartacus features.

Spartacus feature 又分为两局部:来自 @Spartacus/storefront 和 features 文件夹下的 modules.

  1. The SpartacusConfigurationModule, which encapsulates the general Spartacus configuration.

配置信息:

Feature-specific configurations can be kept either in feature modules, or in the SpartacusConfigurationModule. Keeping them in feature modules helps to maintain a good separation of concerns, so it is generally recommended.

feature 相干的配置信息,举荐放到 feature modules 里,从而遵循关注点拆散的准则。

更多 Jerry 的原创文章,尽在:” 汪子熙 ”:

正文完
 0