Configuration
Workers Sites require the latest version of Wrangler.
Commands
wrangler generate proj --siteCreates a project with a Worker serving a generic HTML file and favicon with the directory structure:
├── public # files to serve| ├── favicon.ico| └── index.html├── workers-site| ├── index.js # Workers script that serves the assets| ├── package-lock.json| └── package.json # defines dependencies used by Workers script└── wrangler.tomlAuto-fills
wrangler.tomlwithentry-point(defaults toworkers-site) andbucket(defaults topublic).
wrangler init proj --site- Creates a
wrangler.tomlandworkers-sitefolder. You’ll need to add a value forbucketbased on the local path of folder you’d like to be serve.
- Creates a
wrangler.toml
There are a few specific configuration settings for Workers Sites in your wrangler.toml:
bucketrequired - The directory containing your static assets, path relative to your
wrangler.toml. Example:bucket = "./public".
- The directory containing your static assets, path relative to your
entry-pointoptional - The location of your Worker script, default is
workers-site. Example:entry-point = "./workers-site".
- The location of your Worker script, default is
includeoptional - A list of gitignore-style patterns for files or directories in
bucketyou exclusively want to upload. Example:include = ["upload_dir"].
- A list of gitignore-style patterns for files or directories in
excludeoptional - A list of gitignore-style patterns for files or directories in
bucketyou want to exclude from uploads. Example:exclude = ["ignore_dir"].
- A list of gitignore-style patterns for files or directories in
To learn more about the optional include and exclude fields, visit Ignoring Subsets of Static Assets
.
Example of a wrangler.toml:
wrangler.tomlaccount_id = "95e..."
name = "docs-site-blah"
type = "webpack"
workers_dev = false
[site]
bucket = "./public"
entry-point = "workers-site"
[env.production]
name = "docs-site"
route = "https://example.com/docs*"
zone_id = "351c.."
account_id = "b54f07a.."
[env.staging]
zone_id = "ef47a..."
account_id = "95e5d..."
name = "docs-site-staging"
route = "https://staging.example.com/docs*"
Storage limits
For very exceptionally large pages, Workers Sites might not work for you. There is a 25 MiB limit per page or file.
Ignoring subsets of static assets
Workers Sites require Wrangler - make sure to be on the latest version .
There are cases where users may not want to upload certain static assets to their Workers Sites. In this case, Workers Sites can also be configured to ignore certain files or directories using logic similar to Cargo’s optional include and exclude fields. This means that we use gitignore semantics when declaring which directory entries to include or ignore in uploads.
Exclusively including files/directories
If you want to include only a certain set of files or directories in your bucket, you can add an include field to your
[site] section of wrangler.toml:
[site]
bucket = "./public"
entry-point = "workers-site"
include = ["included_dir"] # must be an array.
Wrangler will only upload files or directories matching the patterns in the include array.
Excluding files/directories
If you want to exclude files or directories in your bucket, you can add an exclude field to your
[site] section of wrangler.toml:
[site]
bucket = "./public"
entry-point = "workers-site"
exclude = ["excluded_dir"] # must be an array.
Wrangler will ignore files or directories matching the patterns in the exclude array when uploading assets to Workers KV.
Include > exclude
If you provide both include and exclude fields, the include field will be used and the exclude field will be ignored.
Default ignored entries
Wrangler will always ignore:
node_modules- Hidden files and directories
- Symlinks
More about include/exclude patterns
You can learn more about the standard patterns used for include and exclude in the gitignore documentation.
Customizing your build
Workers Sites projects use webpack by default. You can bring your own webpack config
, however it is important to be cognizant of your entry and context settings.