Start from existing
Workers Sites require Wrangler ↗ — make sure to use the latest version.
To deploy a pre-existing static site project, start with a pre-generated site. Workers Sites works with all static site generators, for example:
- Hugo ↗
- Gatsby ↗, requires Node
- Jekyll ↗, requires Ruby
- Eleventy ↗, requires Node
- WordPress ↗ (refer to the tutorial on deploying static WordPress sites with Pages)
Getting started
-
Run the
wrangler init
command in the root of your project’s directory to generate a basic Worker:This command adds/update the following files:
wrangler.toml
: The file containing project configuration.package.json
: WranglerdevDependencies
are added.tsconfig.json
: Added if not already there to support writing the Worker in TypeScript.src/index.ts
: A basic Cloudflare Worker, written in TypeScript.
-
Add your site’s build/output directory to the
wrangler.toml
file:The default directories for the most popular static site generators are listed below:
- Hugo:
public
- Gatsby:
public
- Jekyll:
_site
- Eleventy:
_site
- Hugo:
-
Install the
@cloudflare/kv-asset-handler
package in your project: -
Replace the contents of
src/index.ts
with the following code snippet:
-
Run
wrangler dev
ornpx wrangler deploy
to preview or deploy your site on Cloudflare. Wrangler will automatically upload the assets found in the configured directory. -
Deploy your site to a custom domain that you own and have already attached as a Cloudflare zone. Add a
route
property to thewrangler.toml
file.
Learn more about configuring your project.