Build with React
Deploy a React app to an Azion domain from an Azion template, from your GitHub repository, or with the Azion CLI.
You can deploy a React app on Azion from a template in Azion Console, from a GitHub repository you own, or with the Azion CLI. All three routes leave the app running on Azion behind an Azion domain.
Azion serves a React app as a static application. The build writes the compiled app to ./.edge/assets, the deploy uploads that folder to a storage bucket, and an application serves it. For the other frameworks that Azion builds, refer to Frameworks compatibility.
Pick the route you will follow. The prerequisites and the deploy procedure below change with your pick.
Prerequisites
- An Azion account. To create one, refer to Create an account.
- Access to Azion Console. To sign in, refer to How to access Azion Console.
- A GitHub account. The template form connects it when it asks for one.
React templates
A React template is a starter project that Azion builds and deploys for you. The Console route deploys one of these templates:
| Template | Use |
|---|---|
| React Boilerplate | Starter project |
| React with ButterCMS Starter Project | Starter |
React Boilerplate has its own guide, linked in the table. For more information on the other template, refer to Azion Marketplace. In the CLI route, the template picker of azion init lists every template of the React preset.
Deploy the app
Every route builds the React project and creates the Azion resources that serve it. Follow the panel of your route:
To create the project, run azion init with a project name. Select React in the preset picker and a template in the template picker:
The -y option installs the dependencies. The --auto option skips the questions about a local development server and a deploy. For the questions the command asks without these options, refer to Azion CLI init. With the React Boilerplate template, the command prints:
The command creates the project in a my-site folder. Its azion.config.cjs sets the react preset and uploads ./.edge/assets to a storage bucket that workloads can only read. The same file adds a rule named Redirect to index.html, which rewrites routes to /index.html so that React handles routing in the browser. For every setting in that file, refer to azion.config.js.
To build the app, change to the project folder and run azion build:
Azion Bundler runs the template’s react-scripts build script with the react preset, and the compiled app lands in .edge/assets:
To deploy the app, run azion deploy in the project folder:
The command uploads the project and opens the Console page that follows the deploy. It also prints the URL of that page in case no browser opens. When the deploy ends, it prints the URL of the app’s domain. For the full output and every flag, refer to Azion CLI deploy.
To run the app on your machine before you deploy it, refer to Azion CLI dev. To deploy a React project you already have, run azion link in its folder and select the React preset. For more information, refer to Azion CLI link.
Check the site
Every route returns the URL of the app’s Azion domain, in the form https://xxxxxxxxxx.map.azionedge.net. Azion Console shows it on the deploy page, and azion deploy prints it when it ends. Open the URL in a browser to see the React app.
The first deploy can take several minutes to answer from every location; later deploys take about two minutes. Until a location receives the app, the domain answers with a 404 page that reads There's nothing here yet. On that response, wait and request the URL again.