Deploy to Cloudflare Pages
Learn how to deploy your customization to Cloudflare Pages.
Prerequisites
Before you get started, you need to have:
- A Cloudflare account.
- A Merchant Center account and a Project.
- A customization configured in the Merchant Center:
- For Custom Applications, see Managing Custom Applications.
- For Custom Views, see Managing Custom Views.
Configuration
Adding the customization identifier and URL
Depending on the customization type, you'll need to specify either the Custom Application ID or the Custom View ID that was provided to you when you added the customization in the Merchant Center.
You'll also need to specify the production URL from your Cloudflare Pages project. You can keep the standard Cloudflare Pages URL https://<project>.pages.dev
or provide your custom domain.
For Custom Applications, make the following changes to the Custom Application config:
- Add the Custom Application ID to
env.production.applicationId
. - Add the production URL of your Cloudflare site to
env.production.url
.
{"env": {"production": {"applicationId": "ckvtahxl90097sys6har1e6n3","url": "https://<project>.pages.dev"}}}
For Custom Views, make the following changes to the Custom View config:
- Add the Custom View ID to
env.production.customViewId
. - Add the production URL of your Cloudflare project to
env.production.url
.
const config = {env: {production: {customViewId: 'ckvtahxl90097sys6har1e6n3',url: 'https://<project>.pages.dev',},},// ...};
Using environment variables
To avoid hardcoding values (such as the customization identifier or the Project key), you can use variable placeholders in your Custom Application config or Custom View config.
Example of environment variables with Custom Applications:
{"env": {"production": {"applicationId": "${env:APPLICATION_ID}","url": "https://<project>.pages.dev"}}}
Example of environment variables with Custom Views:
const config = {env: {production: {customViewId: '${env:CUSTOM_VIEW_ID}',url: 'https://<project>.pages.dev',},},// ...};
Connect Cloudflare with GitHub
The easiest way to deploy to Cloudflare is to use the GitHub integration.
Follow the steps in Cloudflare Pages to create and import a new Git repository.
Make sure to also install the Cloudflare Workers and Pages GitHub App to grant access to your repository.
Configuring build settings
In the Cloudflare Pages setup process, you need to configure the following things:
Select
React (create-react-app)
as the Framework Preset.Override the Build command with:
yarn build
.In your
package.json
make sure to have the following scripts defined:package.jsonjson{"scripts": {"build": "mc-scripts build"}}Override the Output directory with:
public
.If possible, select or specify the Node.js Version. Recommended version is
>= v14
.
If your customization config requires environment variables, make sure to provide them in your Account Home > Pages > Pages project > Settings > Environment variables.
Test your deployment
Install your customization in the Merchant Center to access it within your Projects:
- For Custom Applications, see Managing Custom Applications. You can also use deployment previews to test the application before releasing it to the production environment.
- For Custom Views, see Managing Custom Views.