API 浏览器
Quasar CLI with Webpack - @quasar/app-webpack
部署 SSR

部署为 SPA 或 PWA 时,Quasar CLI 生成的 distributables 文件夹可以由静态 Web 服务器提供服务。但是,SSR(服务器端渲染)构建并非如此。在这种情况下,你的可分发包也包含你的生产环境 Web 服务器 - 你可以从 /src-ssr 进行调整。

¥When deploying as a SPA or PWA, the distributables folder that gets generated by Quasar CLI can be served by a static webserver. However, this is not the case with an SSR (Server-side Render) build. Your distributables, in this case, contain your production webserver too – which can be tweaked from /src-ssr.

默认情况下,SSR 分发包使用 Express,但你可以将其替换为你选择的 Web 服务器。

¥By default, the SSR distributables use Express, but you can replace it with your webserver of choice.

无服务器(Serverless)

¥Serverless

如果你要部署到无服务器服务,请阅读 SSR 生产环境导出 以了解如何准备。

¥If you are deploying to a Serverless service, then please read about SSR Production Export on how to prepare for it.

Distributables 文件夹(The Distributables Folder)

¥The Distributables Folder

在 SSR 模式 ($ quasar build -m ssr) 下构建应用后,生成的文件夹包含一个独立的 Web 服务器,该服务器已针对 SSR 进行了调整。

¥After building your app on SSR mode ($ quasar build -m ssr) the folder that gets generated contains a standalone webserver tweaked for serving with SSR.

你会注意到它包含一个自己的 package.json 文件。它定义了一个名为 “start” 的 npm 脚本:

¥You’ll notice that it contains a package.json file of its own. It has an npm script defined, called “start”:

"scripts": {
  "start": "node index.mjs"
}

所以部署时你需要做的是将这个 distributables 文件夹复制到你的服务器上,使用 yarn/npm 安装其中的依赖,然后运行 ​​$ yarn start。这将启动 Web 服务器并开始监听连接。

¥So what you need to do when deploying is to copy this distributables folder on your server, yarn/npm install the dependencies inside it, then run $ yarn start. This boots up the webserver and starts listening for connections.

提示

构建应用后生成的可分发文件文件夹是独立的。它不需要项目文件夹的其余部分即可运行,也不依赖于 @quasar/cli 的安装。

¥The distributables folder generated after building your app is standalone. It does NOT require the rest of your project folder to work and it does NOT depend on @quasar/cli being installed.

提升性能(Enhancing Performance)

¥Enhancing Performance

默认情况下,Web 服务器仅在可用服务器的一个核心上运行。你可以做的是让它使用所有核心。有一个解决方案:PM2

¥By default, the webserver runs on only one of the available server’s cores. What you could do is make it use all cores. There is a solution for this: PM2.

在服务器上安装 PM2 后,你的 npm 启动脚本可能如下所示:

¥After installing PM2 on your server, your npm start script can look like this instead:

"scripts": {
  "start": "pm2 start index.mjs"
}

使用 Cleavr 部署(Deploying with Cleavr)

¥Deploying with Cleavr

你可以使用 Cleavr 将 Quasar SSR 应用部署到几个流行的 VPS 提供商。Cleavr 将自动为你的应用设置启用集群模式的 PM2。

¥You can use Cleavr to deploy Quasar SSR apps to several popular VPS providers. Cleavr will automatically set up PM2 with cluster mode enabled for your app.

在 Cleavr 中添加一个新的 NodeJS SSR 站点,然后使用以下命令配置 Web 应用设置:

¥Add a new NodeJS SSR site to Cleavr and then configure the web app settings with the following:

  • 入口点:index.js

    ¥Entry point: index.js

  • 构建命令:npx quasar build --mode ssr

    ¥Build command: npx quasar build --mode ssr

  • 工件路径:dist/ssr

    ¥Artifact path: dist/ssr