In this section, we will discuss the deployment of the project. We assume that you have completed the development of the project and now need to deploy the project online. You need to consider the following aspects:
Before deployment, we need to first build the project in the production environment and preview it locally to ensure that the project can run normally. In Rspress projects, we can use the following scripts
commands to build and preview:
For the preview command, you can specify the preview port number through the --port
parameter, such as rspress preview --port 8080
.
It is worth noting that the final output will be output to the doc_build
directory under the project root directory. The content in this directory is what we need to deploy.
We can divide the deployment output into two parts: HTML files and static resources. HTML files refer to the HTML files in the output directory. These files are the files we finally deploy to the server.
The so-called static resources refer to the static
directory in the output directory, which contains the JavaScript, CSS, images and other static resources required by the project. When deploying, if you want to put these static resources on the CDN to ensure better access performance, instead of directly putting them on the server like HTML, then you need to configure the prefix of the static resources so that the project can correctly reference these static resources. You can complete it through builderConfig.output.assetPrefix
:
In this way, when referencing static resources in HTML, the prefix will be automatically added, for example:
When deploying, we may need to deploy the project to a subpath. For example, if you plan to deploy your site to https://foo.github.io/bar/
, then you should set the base
parameter to "/bar/"
:
After completing the above configuration, we can deploy the output to the server. You have many choices, such as GitHub Pages
, Netlify
, Vercel
, etc. Here we take GitHub Pages
and Netlify
as examples to explain how to deploy.
If your project is hosted on GitHub
, then you can deploy via GitHub Pages
. GitHub Pages
is a static website hosting service provided by GitHub
, which allows you to directly deploy your project to GitHub
without having to build your own server.
First, you need to create a file named .github/workflows/deploy.yml
in the project root directory, with the following content:
In the Pages
column of the repository Settings
interface, you can choose GitHub Actions
as the deployment source.
When you push the code to the main
branch, GitHub Actions
will automatically execute the deployment process. You can view the progress of the deployment in the Actions
column. After the deployment is complete, you can access your site through https://<username>.github.io/<repository>/
.
Netlify
is a Web application deployment platform, which allows you to directly deploy your project to Netlify
without having to build your own server.
Deploying a project on Netlify
is very simple. You only need to import your Github repository, and then configure some basic information to deploy. Just configure the following two fields:
Build command
: Build command, here we fill in the build command in the project, such as npm run build
.Publish directory
: Output directory, here we fill in the output directory doc_build
in the project.Then click the Deploy site
button to complete the deployment.
If you want to bind your site to your own domain, you can configure it in the Domain management
column of Netlify
. The specific configuration method can refer to the Netlify official documentation.
You can deploy your Rspress site on Kinsta.
Login or create an account to view your MyKinsta dashboard.
Authorize Kinsta with your Git provider.
Select Static Sites from the left sidebar and press Add sites.
Select the repository and branch you want to deploy.
During the build settings, Kinsta will automatically try to fill out the Build command, Node version, and Publish directory. If it won't, fill out the following:
npm run build
18.16.0
doc_build
Click the Create site.
Zeabur is a platform for deploying services instantly, which allows you to directly deploy your Rspress site without any other configurations.
First of all, you need to create a Zeabur account. Then, follow the instructions to create a project and install a GitHub app to authorize Zeabur get your Rspress repository.
Click on Deploy New Service
and import your Rspress repository, the deployment will be started automatically and Zeabur will recognize that your site is built with Rspress.
The deployment will be finished in a minute, you can also bind a free sub domain provided by Zeabur or your own domain for this site.