Deploy to Surge
Learn how to deploy your customization to Surge.
Prerequisites
Before you get started, you need to have:
- A Surge account, using the
surge
CLI. - 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 Surge project. You can keep the standard Surge URL https://<project>.surge.sh
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 from your Surge project to
env.production.url
.
{"env": {"production": {"applicationId": "ckvtahxl90097sys6har1e6n3","url": "https://<project>.surge.sh"}}}
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 Surge project to
env.production.url
.
const config = {env: {production: {customViewId: 'ckvtahxl90097sys6har1e6n3',url: 'https://<project>.surge.sh',},},// ...};
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>.surge.sh"}}}
Example of environment variables with Custom Views:
const config = {env: {production: {customViewId: '${env:CUSTOM_VIEW_ID}',url: 'https://<project>.surge.sh',},},// ...};
Production bundles
The main command to create the production bundles is mc-scripts build
. The output folder is public
, which is what is going to be uploaded to Surge.
For more information, see Going to production.
To properly support client-side routing, you need to rename the index.html
file to 200.html
before uploading the static files.
Deploying to Surge
Use the Surge CLI to upload the static files.
surge public https://<project>.surge.sh
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.