rerumaccusamus
Version:
The meta-framework suite designed from scratch for frontend-focused modern web development.
27 lines (19 loc) • 838 B
Markdown
title: 启用 SSR
上一小节我们学习了如何使用 Modern.js 调试项目,本小节我们将学习如何快速开启 SSR(服务端渲染)。
在项目根目录 `package.json` 下,添加 `modernConfig` 字段:
添加如下配置:
```js title="package.json"
"modernConfig": {
"server": {
"ssr": true
}
}
```
这样项目的 SSR 就已经开启了,重新执行 `pnpm run dev` 看看效果吧。
用 Chrome 打开 `view-source:http://localhost:8080/`,查看 HTML 文件源代码,可以看到 root 根元素下存在已经在服务器端渲染好的 HTML。
:::note 注
Modern.js 框架支持 Serverless SSR,不需要自建 server 和部署运维,开发者可以专注于 App 的开发。
除此之外,Modern.js 也支持 Serverless BFF,两者都会在后面的章节详细介绍。
:::