Deploy a Blazor site
Creating a new Blazor WASM project
There are two types of Blazor projects: Blazor Server applications, which run on the server, and Blazor WASM (WebAssembly), which run in the browser. Since Blazor Server is not static, this guide will use Blazor WASM.
Create a new Blazor WASM application by running the following command in a new directory:
$ dotnet new blazorwasm -o my-blazor-project
Create the build script
To deploy, Cloudflare Pages will need a way to build the Blazor project. In the project’s directory root, create a
build.sh file. Populate the file with this:
#!/bin/shcurl -sSL https://dot.net/v1/dotnet-install.sh > dotnet-install.shchmod +x dotnet-install.sh./dotnet-install.sh -c 7.0 -InstallDir ./dotnet./dotnet/dotnet --version./dotnet/dotnet publish -c Release -o output
Before you continue
.gitignore file ensures that only what is needed gets pushed onto your GitHub repository. Create a
.gitignore file by running the following command:
$ dotnet new gitignore
Create a GitHub repository
$ git init$ git remote add origin https://github.com/<your-gh-username>/<repository-name>$ git add .$ git commit -m "Initial commit"$ git branch -M main$ git push -u origin main
Deploy with Cloudflare Pages
To deploy your site to Pages:
- Log in to the and select your account.
- In Account Home, select Workers & Pages.
- Select Create application > Pages > Connect to Git.
Select the new GitHub repository that you created and, in the Set up builds and deployments section, provide the following information:
After configuring your site, you can begin your first deploy. You should see Cloudflare Pages installing
dotnet, your project dependencies, and building your site, before deploying it.
After deploying your site, you will receive a unique subdomain for your project on
Every time you commit new code to your Blazor site, Cloudflare Pages will automatically rebuild your project and deploy it. You will also get access to on new pull requests, so you can preview how changes look to your site before deploying them to production.
A file is over the 25 MiB limit
If you receive the error message
Error: Asset "/opt/buildhome/repo/output/wwwroot/_framework/dotnet.wasm" is over the 25MiB limit, resolve this by doing one of the following actions:
- Remove the
*.wasmfiles from the output (
rm output/wwwroot/_framework/*.wasm) and modify your Blazor application to instead.