動態

詳情 返回 返回

SAP Spartacus Reference App Structure - 動態 詳情

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的原創文章,盡在:"汪子熙":

user avatar damonxiaozhi 頭像 lvweifu 頭像 xiaoxiansheng_5e75673e1ae30 頭像 risejl 頭像 dblens_com 頭像
點贊 5 用戶, 點贊了這篇動態!
點贊

Add a new 評論

Some HTML is okay.