天天看點

SAP Spartacus 伺服器端渲染檔案的 build 過程

SAP Spartacus 根目錄下有個 server.ts 檔案。整個檔案的入口是 run 函數:

SAP Spartacus 伺服器端渲染檔案的 build 過程
run 函數裡,開啟一個 伺服器,監聽在 4000 端口上:
SAP Spartacus 伺服器端渲染檔案的 build 過程

伺服器執行個體通過 app 函數傳回:

首先利用一個NgExpressEngineDecorator 獲得 NgUniversal engine 執行個體,然後将該 engine 同 express 傳回的 server 執行個體進行綁定:

所有的靜态檔案,通過 browser 檔案夾裡的檔案傳回:

所有的正常路由,使用 Universal Engine 響應。

該 server.ts 檔案的引用,定義在 tsconfig.server.json 裡:

SAP Spartacus 伺服器端渲染檔案的 build 過程
另一個 src/main.server.ts 檔案:
SAP Spartacus 伺服器端渲染檔案的 build 過程

而這個 tsconfig.server.json 檔案什麼時候被使用呢?

tsconfig.server.json 擴充 tsconfig.app.json,而後者又擴充 tsconfig.json:

SAP Spartacus 伺服器端渲染檔案的 build 過程

A given Angular workspace contains several TypeScript configuration files.

一個 Angular workspace 裡包含了若幹 TypeScript 配置檔案。

At the root tsconfig.json file specifies the base TypeScript and Angular compiler options that all projects in the workspace inherit.

根目錄下的 tsconfig.json 檔案指定了 TypeScript 和 Angular 編譯器設定,該 workspace 下所有的項目都會繼承。

A TypeScript configuration can inherit settings from another file using the extends property.

使用 extends 關鍵字,TypeScript configuration 可以從另一個檔案繼承其定義好的屬性。