This guide shows you how to deploy a UmiJS application to Edgio.
Example
Prerequisites
Before proceeding, you will need an Edgio property. Create one now if you do not already have one.
System Requirements
Sign up for Edgio
Deploying requires an account on Edgio. Sign up here for free.
Install the Edgio CLI
If you have not already done so, install the Edgio CLI.
Bash
1npm i -g @edgio/cli@^6.0.0
Create a new UmiJS app
If you don’t already have a UmiJS app, create one by running the following:
Bash
1mkdir myapp && cd myapp2npx @umijs/create-umi-app
You can verify your app works by running it locally with:
Bash
1npm install && npm run start
Configuring your UmiJS app for Edgio
Initialize your project
In the root directory of your project run
edgio init
:Bash
1edgio init --edgioVersion ^6.0.0
This will automatically update your
package.json
and add all of the required Edgio dependencies and files to your project. These include:- The
@edgio/core
package - Allows you to declare routes and deploy your application on Edgio - The
@edgio/prefetch
package - Allows you to configure a service worker to prefetch and cache pages to improve browsing speed edgio.config.js
- A configuration file for Edgioroutes.js
- A default routes file that sends all requests to UmiJS.
Configure the routes
Update
routes.js
at the root of your project to the following:JavaScript
1// This file was added by edgio init.2// You should commit this file to source control.34import { Router } from '@edgio/core/router'56export default new Router()7 // Create serveStatic route for each file in the folder dist with a cache-control header of 's-maxage=315360000'8 .static('dist')9 .fallback(({ appShell }) => {10 appShell('dist/index.html')11 })
Refer to the CDN-as-code guide for the full syntax of the
routes.js
file and how to configure it for your use case.Run the UmiJS app locally on Edgio
Create a production build of your app by running the following in your project’s root directory:
Bash
1npm run build
Test your app with the Sites on your local machine by running the following command in your project’s root directory:
Bash
1edgio dev
Load the site http://127.0.0.1:3000
Deploying
Create a production build of your app by running the following in your project’s root directory:
Bash
1npm run build
Deploy your app to the Sites by running the following command in your project’s root directory:
Bash
1edgio deploy
Refer to the Deployments guide for more information on the
deploy
command and its options.