Skip to content

Commit

Permalink
[docs] update wrangler.toml example to wrangler@2 (#5187)
Browse files Browse the repository at this point in the history
* fix: update wrangler.toml example to wrangler@2

Updates the example provided for `wrangler.toml` file for
the `adapter-cloudflare-workers` documentation, to follow
the specs on wrangler@2.

* align README with the error message printed when wrangler.toml is missing

* changeset

Co-authored-by: Rich Harris <hello@rich-harris.dev>
  • Loading branch information
LeoBorai and Rich-Harris authored Jun 21, 2022
1 parent a48a30d commit f5b409f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 40 deletions.
5 changes: 5 additions & 0 deletions .changeset/hip-kangaroos-check.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/adapter-cloudflare-workers': patch
---

Simplify example wrangler.toml, and fix outdated README
58 changes: 19 additions & 39 deletions packages/adapter-cloudflare-workers/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,62 +33,42 @@ export default {

## Basic Configuration

**You will need [Wrangler](https://developers.cloudflare.com/workers/cli-wrangler/install-update) installed on your system**

This adapter expects to find a [wrangler.toml](https://developers.cloudflare.com/workers/platform/sites/configuration) file in the project root. It will determine where to write static assets and the worker based on the `site.bucket` and `site.entry-point` settings.

Generate this file using `wrangler` from your project directory

```sh
wrangler init --site my-site-name
```

Now you should get some details from Cloudflare. You should get your:

1. Account ID
2. And your Zone-ID (Optional)

Get them by visiting your [Cloudflare dashboard](https://dash.cloudflare.com) and click on any domain. There, you can scroll down and on the left, you can see your details under **API**.

Then configure your sites build directory and your account-details in the config file:
This adapter expects to find a [wrangler.toml](https://developers.cloudflare.com/workers/platform/sites/configuration) file in the project root. It should look something like this:

```toml
account_id = 'YOUR ACCOUNT_ID'
zone_id = 'YOUR ZONE_ID' # optional, if you don't specify this a workers.dev subdomain will be used.
name = "<your-service-name>"
account_id = "<your-account-id>"

main = "./.cloudflare/worker.js"
site.bucket = "./.cloudflare/public"

type = "javascript"
build.command = "npm run build"

[build]
# Assume it's already been built. You can make this "npm run build" to ensure a build before publishing
command = ""
compatibility_date = "2021-11-12"
workers_dev = true
```

[build.upload]
format = "modules"
main = "./worker.mjs"
`<your-service-name>` can be anything. `<your-account-id>` can be found by logging into your [Cloudflare dashboard](https://dash.cloudflare.com) and grabbing it from the end of the URL:

[site]
bucket = "./.cloudflare/assets"
entry-point = "./.cloudflare/worker"
```
https://dash.cloudflare.com/<your-account-id>
```

It's recommended that you add the `build` and `workers-site` folders (or whichever other folders you specify) to your `.gitignore`.
> It's recommended that you add the `.cloudflare` directory (or whichever directories you specified for `main` and `site.bucket`) to your `.gitignore`.
Now, log in with wrangler:
You will need to install [wrangler](https://developers.cloudflare.com/workers/wrangler/get-started/) and log in, if you haven't already:

```sh
```
npm i -g wrangler
wrangler login
```

Build your project and publish it:
Then, you can build your app and deploy it:

```sh
npm run build && wrangler publish
wrangler publish
```

**You are done!**

More info on configuring a cloudflare worker site can be found [here](https://developers.cloudflare.com/workers/platform/sites/start-from-existing)

## Changelog

[The Changelog for this package is available on GitHub](https://github.com/sveltejs/kit/blob/master/packages/adapter-cloudflare-workers/CHANGELOG.md).
1 change: 0 additions & 1 deletion packages/adapter-cloudflare-workers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ function validate_config(builder) {
name = "<your-site-name>"
account_id = "<your-account-id>"
route = "<your-route>"
main = "./.cloudflare/worker.js"
site.bucket = "./.cloudflare/public"
Expand Down

0 comments on commit f5b409f

Please sign in to comment.