SAP Spartacus SSR学习笔记 - 如何启用SAP Spartacus服务器端渲染模式

https://sap.github.io/spartacus-docs/server-side-rendering-in-spartacus/

In Spartacus, server-side rendering allows you to render static versions of pages on the server side. This speeds up response times, assists with SEO, and allows the application to render more quickly. After Angular has bootstrapped, users of your site will have the full experience.

服务器端渲染页面的静态版本。服务器端渲染(Server Side Rendering,SSR)加快了应用的响应速度,有助于页面SEO-搜索引擎优化。

如何启用Spartacus SSR

The recommended way to add SSR support to your Spartacus application is to use schematics. With a single command, all required files are added automatically, and all modifications for SSR support are done automatically as well. To add SSR support to your Spartacus application, run the following command:

ng add @spartacus/schematics --ssr

Installation Steps for Spartacus Development

设置environment.prod.ts里的occBaseUrl:

关掉PWA:

As soon as Spartacus is installed in PWA mode, a service worker is installed, and it serves a cached version of index.html, along with the js files. This results in SSR being completely skipped. The following steps describe how to turn off PWA.

app.module.ts里,关闭pwa:

yarn build:core:lib

building Angular package

Compiling TypeScript sources through ngc

Bundling to FESM2015

Spartacus/core built完毕
Angular package built完毕

built输出位于projects/core和dist/core文件夹下面:

storefrontlib build完毕:

organization/Administration/core built完毕:

总共花费400秒

然后:Build your local Spartacus shell app by running the following command:

yarn build --prod

实际上执行的命令是:

ng build storefrontapp --prod --prod


总共花费215秒:

Build the SSR version of your shell app by running the following command:

yarn build:ssr

72秒结束:

最后一个步骤:
yarn serve:ssr


原来是用的node express server

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


你可能感兴趣的:(SAP Spartacus SSR学习笔记 - 如何启用SAP Spartacus服务器端渲染模式)