[英]Angular Universal Production Build Process
I'm using Angular Universal 10 and I want to prerender my site.我正在使用 Angular Universal 10,我想预渲染我的网站。
I'm confused on the proper build process for a production environment.我对生产环境的正确构建过程感到困惑。
Angular gives these two commands: Angular 给出了这两个命令:
"build:ssr": "ng build --prod && ng run my-app.spa:server:production",
"prerender": "ng run my-app.spa:prerender"
Is it enough to just do this to get a production ready output?这样做是否足以让 output 做好生产准备?
npm run prerender
Or do I need to run both of these?还是我需要同时运行这两个?
npm run build:ssr
npm run prerender
What's the difference?有什么不同?
To understand the difference between these two commands, run one and look at the compiled output.要了解这两个命令之间的区别,请运行一个并查看已编译的 output。
The first command npm run build:ssr
will compile your site into a file that can be served using a NodeJS Express app, as you see in server.ts
.第一个命令
npm run build:ssr
会将您的站点编译为可以使用 NodeJS Express 应用程序提供的文件,如您在server.ts
中所见。 This way you will still only have one index.html file, but depending on your route, universal will deliver a rendered html file for that route to the browser.这样,您仍然只有一个 index.html 文件,但根据您的路线,universal 将为该路线提供一个渲染的 html 文件到浏览器。 So, you are rendering on the server, server-side rendering .
所以,你在服务器上渲染,服务器端渲染。
The second command npm run prerender
will use the server.ts
to "pre-render" each of the routes with their own individual index.html file, all placed in a directory structure according to your routes.第二个命令
npm run prerender
将使用server.ts
来“预渲染”每个带有自己单独索引的路由。html 文件,所有这些都根据您的路由放置在目录结构中。 The compiled code looks like a traditional static website.编译后的代码看起来像一个传统的 static 网站。 So, you are rendering before you deploy, pre-rendering .
因此,您在部署之前进行渲染,预渲染.
So which is best for you?那么哪个最适合您?
build:ssr
prerender
This post on Medium has a pretty good overview with more detailed information. 这篇关于 Medium 的帖子有一个很好的概述,其中包含更详细的信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.