Start from scratch
This guide shows how to quickly start a new Workers Sites project from scratch.
Getting started
-
Ensure you have the latest version of git ↗ and Node.js ↗ installed.
-
In your terminal, clone the
worker-sites-template
starter repository. The following example creates a project calledmy-site
: -
Run
npm install
to install all dependencies. -
You can preview your site by running the
wrangler dev
command: -
Deploy your site to Cloudflare:
Project layout
The template project contains the following files and directories:
public
: The static assets for your project. By default it contains anindex.html
and afavicon.ico
.src
: The Worker configured for serving your assets. You do not need to edit this but if you want to see how it works or add more functionality to your Worker, you can editsrc/index.ts
.wrangler.toml
: The file containing project configuration. Thebucket
property tells Wrangler where to find the static assets (e.g.site = { bucket = "./public" }
).package.json
/package-lock.json
: define the required Node.js dependencies.
Customize wrangler.toml
:
-
Change the
name
property to the name of your project: -
Consider updating
compatibility_date
to today’s date to get access to the most recent Workers features: -
Deploy your site to a custom domain that you own and have already attached as a Cloudflare zone:
Learn more about configuring your project.