Skip to content

Commit f6d3fb2

Browse files
PeshekDotDevConnor Peshek
andauthored
Replace wrangler preview with wrangler dev. (#512)
Co-authored-by: Connor Peshek <[email protected]>
1 parent 4380033 commit f6d3fb2

File tree

1 file changed

+60
-53
lines changed

1 file changed

+60
-53
lines changed

products/workers/src/content/learning/getting-started.md

Lines changed: 60 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ $ wrangler --version
4747

4848
## 3. Configure the Workers CLI
4949

50-
Now that Wrangler is installed, you'll need to give it an API Token for your Cloudflare account. Run the command `wrangler login` and Wrangler will ask to automatically open your web browser to log into your Cloudflare account. If you are in an environment that doesn't have a GUI, you can copy and paste the url into a browser and log in.
50+
Now that Wrangler is installed, you'll need to give it an API Token for your Cloudflare account.
51+
52+
Run the command `wrangler login` and Wrangler will ask to automatically open your web browser to log into your Cloudflare account. If you are in an environment that doesn't have a GUI, you can copy and paste the url into a browser and log in.
5153

5254
```bash
5355
$ wrangler login
@@ -195,55 +197,68 @@ For inspiration, visit [Built with Workers](https://workers.cloudflare.com/built
195197

196198
## 6. Preview your project
197199

198-
When you’re ready to preview your code, run Wrangler’s `preview` command:
200+
In order to preview our Worker, we're going to need to configure our project by adding our `Account ID` to our project's `wrangler.toml`.
199201

200-
```sh
201-
~/my-worker $ wrangler preview --watch
202+
Run the command `wrangler whoami` and copy your `Account ID`.
203+
204+
```bash
205+
$ wrangler whoami
206+
👋 You are logged in with an API Token, associated with the email '<Your Email>'!
207+
208+
+----------------------------------+----------------------------------+
209+
| Account Name | Account ID |
210+
+----------------------------------+----------------------------------+
211+
| Your Account | $yourAccountId |
212+
+----------------------------------+----------------------------------+
202213
```
203214

204-
This command will build your project, upload it to a unique URL, and open a tab in your browser to view it. This allows you to quickly test your project running on the actual Workers runtime, and optionally, even share it with others too.
215+
Then, open up your project's `wrangler.toml` and paste it in as the value for the `account_id` field.
216+
217+
```toml
218+
---
219+
filename: wrangler.toml
220+
highlight: [2]
221+
---
222+
name = "my-worker"
223+
account_id = "$yourAccountId"
224+
```
205225

206-
The `--watch` flag tells Wrangler to watch your Workers project directory for changes, and will **automatically update** the preview tab live with the latest URL.
226+
Once you've done that, you’re ready to preview your code. Run the `wrangler dev` command:
227+
228+
```sh
229+
~/my-worker $ wrangler dev
230+
💁 watching "./"
231+
👂 Listening on http://127.0.0.1:8787
232+
```
233+
234+
This command will build your project, run it locally, and return a url for you to visit to preview the worker.
207235

208236
<Aside header="A note about building">
209237

210-
Running `wrangler preview` and `wrangler publish` both run `wrangler build` beforehand automatically, but it can be useful to run `build` separately to check for errors. Running `wrangler build` installs the necessary dependencies for your project and compiles it to make it ready for previewing or deployment. Learn [more about Wrangler](/cli-wrangler/commands).
238+
Running `wrangler dev` and `wrangler publish` both run `wrangler build` beforehand automatically, but it can be useful to run `build` separately to check for errors. Running `wrangler build` installs the necessary dependencies for your project and compiles it to make it ready for previewing or deployment. Learn [more about Wrangler](/cli-wrangler/commands).
211239

212240
</Aside>
213241

214242
--------------------------------
215243

216244
## 7. Configure your project for deployment
217245

218-
In order to publish your Workers project on Cloudflare’s global cloud network, you’ll need to configure your project's `wrangler.toml` with an **Account ID**.
219-
220-
If deploying on a free workers.dev subdomain, that’s it. If you’re deploying onto your own domain, you’ll additionally need to configure the project with a **Zone ID**.
221-
222-
### 7a. Obtaining your Account ID (and Zone ID)
223-
224-
#### workers.dev
225-
226-
For workers.dev domains, you will just need the Account ID. The easiest way to get it is by running `wrangler whoami`.
227-
228-
However, you can also find your Account ID in the Cloudflare dashboard with the following steps:
229-
230-
1. [**Log in** to your Cloudflare account](https://dash.cloudflare.com/login) and select **Workers**.
231-
2. On the right, look for **Account ID** and click **Click to copy** below the input.
232-
233-
#### Registered domains
234-
235-
For domains that you have registered on Cloudflare, you need both IDs:
236-
237-
1. [**Log in** to your Cloudflare account](https://dash.cloudflare.com/login) and select the desired domain.
238-
2. Select the **Overview** tab on the navigation bar.
239-
3. Scroll down until you see both **Zone ID** and **Account ID* on the right.
240-
4. Click **Click to copy** below the input to each.
246+
To configure your project, we need to fill in a few missing fields in the `wrangler.toml` file in the root of the generated project. This file contains the information Wrangler needs to connect to the Cloudflare Workers API and publish your code.
241247

242-
### 7b. Configuring your project
248+
You should have already filled in the `account_id` field in the last step. If you didn't, you can get your `Account ID` by running `wrangler whoami`.
243249

244-
To configure your project, we need to fill in a few missing fields in the `wrangler.toml` file in the root of the generated project. This file contains the information Wrangler needs to connect to the Cloudflare Workers API and publish your code.
250+
```bash
251+
$ wrangler whoami
252+
👋 You are logged in with an API Token, associated with the email '<Your Email>'!
253+
254+
+----------------------------------+----------------------------------+
255+
| Account Name | Account ID |
256+
+----------------------------------+----------------------------------+
257+
| Your Account | $yourAccountId |
258+
+----------------------------------+----------------------------------+
259+
```
245260

246-
For now, fill in just the `account_id` field with the value found from running `wrangler whoami` or from looking in your dashboard.
261+
Then, paste it into your `wrangler.toml` as the value for the `account_id` field.
247262

248263
```toml
249264
---
@@ -266,29 +281,19 @@ account_id = "$yourAccountId"
266281
type = "webpack"
267282
```
268283

269-
Finally, we need to tell Wrangler where we want to deploy our project.
270-
271-
#### Configure for deploying to workers.dev
272-
273-
With the `workers_dev` key in `wrangler.toml` set to `true`, Wrangler will publish your project to your `workers.dev` subdomain.
274-
275-
```toml
276-
---
277-
filename: wrangler.toml
278-
highlight: [4]
279-
---
280-
name = "my-worker"
281-
account_id = "$yourAccountId"
282-
type = "webpack"
283-
workers_dev = true
284-
```
285-
286-
When deploying to a workers.dev subdomain, the **name** field will be used as the secondary subdomain for the deployed script, e.g. `my-worker.my-subdomain.workers.dev`.
284+
By default, this project will deploy to your workers.dev subdomain. When deploying to a workers.dev subdomain, the **name** field will be used as the secondary subdomain for the deployed script, e.g. `my-worker.my-subdomain.workers.dev`.
287285

288286
#### (Optional) Configure for deploying to a registered domain
289287

290288
To publish your application on a domain you own, and not a workers.dev subdomain, you can add a `route` key to your `wrangler.toml`.
291289

290+
You can get your `zone_id` with the following steps:
291+
292+
1. [**Log in** to your Cloudflare account](https://dash.cloudflare.com/login) and select the desired domain.
293+
2. Select the **Overview** tab on the navigation bar.
294+
3. Scroll down until you see both **Zone ID** on the right.
295+
4. Click **Click to copy** below the input.
296+
292297
Wrangler’s [environments feature](/platform/environments) allows us to specify multiple different deploy targets for our application. Let's add a `production` environment, passing in a `zone_id` and `route`:
293298

294299
```toml
@@ -317,7 +322,7 @@ If your route is configured to a hostname, you will need to add a DNS record to
317322

318323
## 8. Publish your project
319324

320-
With our project configured, it’s time to publish it. The way we’ve configured it we have two deploy targets we can publish to.
325+
With our project configured, it’s time to publish it.
321326

322327
To deploy to our workers.dev subdomain, we can run:
323328

@@ -334,7 +339,9 @@ __Note:__ When pushing to workers.dev project for the first time, you may initia
334339

335340
</Aside>
336341

337-
To deploy to our “production” environment we set in our `wrangler.toml`, we can pass the `--env` flag to the command:
342+
#### (Optional) Publish your project to a registered domain
343+
344+
To deploy to our production environment we set in our `wrangler.toml` in the optional configuration step, we can pass the `--env` flag to the command:
338345

339346
```sh
340347
---

0 commit comments

Comments
 (0)