You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/docs/workers/local-development/index.mdx
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,8 +11,8 @@ Cloudflare Workers provides two primary ways to develop and test your code local
11
11
12
12
You can test changes locally using the following:
13
13
14
-
-**Wrangler’s built-in dev command**[`wrangler dev`](/workers/wrangler/commands/#dev), which uses [`workerd`](https://github.com/cloudflare/workerd) and Miniflare to simulate production behavior and resource bindings locally. Wrangler also offers the option to develop against remote resources with `wrangler dev --remote`, allowing you to test directly with data stored on Cloudflare's network.
14
+
-**Wrangler’s built-in dev command**[`wrangler dev`](/workers/wrangler/commands/#dev), which uses [`workerd`](https://github.com/cloudflare/workerd) and Miniflare to simulate production behavior and resource bindings locally. Wrangler also offers the option to [develop against remote resources](/workers/local-development/wrangler/#develop-using-remote-resources-and-bindings) with `wrangler dev --remote`, allowing you to test directly with data stored on Cloudflare's network.
15
15
16
-
- The **Cloudflare Vite plugin** (`@cloudflare/vite-plugin`), which integrates directly with Vite and runs your code in the same `workerd` runtime, while also offering features like [hot module replacement (HMR)](https://vite.dev/guide/features.html#hot-module-replacement). The Vite plugin is currently considered in **beta**.
16
+
- The **Cloudflare Vite plugin** (`@cloudflare/vite-plugin`), which integrates directly with [Vite](https://vite.dev/) and runs your code in the [Worker Runtime](/workers/reference/how-workers-works/) ([`workerd`](https://github.com/cloudflare/workerd)), while also offering features like [hot module replacement (HMR)](https://vite.dev/guide/features.html#hot-module-replacement). The Vite plugin is currently in open beta.
17
17
18
18
Both approaches aim to provide confidence that your local environment will closely match the production runtime, removing the need to [test against remote resources](#develop-using-remote-resources-and-bindings).
Copy file name to clipboardExpand all lines: src/content/docs/workers/local-development/wrangler.mdx
+14-12Lines changed: 14 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,6 +7,8 @@ head: []
7
7
description: Locally develop and test changes with `wrangler dev`
8
8
---
9
9
10
+
import { PackageManagers } from"~/components";
11
+
10
12
## Start a local development server
11
13
12
14
:::note
@@ -19,9 +21,7 @@ Users new to Wrangler CLI and Cloudflare Workers should visit the [Wrangler Inst
19
21
20
22
Wrangler provides a [`dev`](/workers/wrangler/commands/#dev) command that starts a local server for developing your Worker. Make sure you have `npm` installed and run the following in the folder containing your Worker application:
`wrangler dev` will run the Worker directly on your local machine. `wrangler dev` uses a combination of `workerd` and [Miniflare](https://github.com/cloudflare/workers-sdk/tree/main/packages/miniflare), a simulator that allows you to test your Worker against additional resources like KV, Durable Objects, WebSockets, and more.
27
27
@@ -65,9 +65,11 @@ When you run `wrangler dev` Wrangler stores local resources in a `.wrangler/stat
65
65
66
66
If you prefer to specify a directory, you can use the [`--persist-to`](/workers/wrangler/commands/#dev) flag with `wrangler dev` like this:
67
67
68
-
```sh
69
-
npx wrangler dev --persist-to <DIRECTORY>
70
-
```
68
+
<PackageManagers
69
+
type="exec"
70
+
pkg="wrangler"
71
+
args="dev --persist-to <DIRECTORY>"
72
+
/>
71
73
72
74
Using this will write all local storage and cache to the specified directory instead of `.wrangler`.
73
75
@@ -90,9 +92,11 @@ The following [Wrangler commands](/workers/wrangler/commands/) have a `--local`
90
92
91
93
If using `--persist-to` to specify a custom folder with `wrangler dev` you should also add `--persist-to` with the same directory name along with the `--local` flag when running the commands above. For example, to put a custom KV key into a local namespace via the CLI you would run:
92
94
93
-
```sh
94
-
npx wrangler kv key put test 12345 --binding MY_KV_NAMESPACE --local --persist-to worker-local
95
-
```
95
+
<PackageManagers
96
+
type="exec"
97
+
pkg="wrangler"
98
+
args="kv key put test 12345 --binding MY_KV_NAMESPACE --local --persist-to worker-local"
99
+
/>
96
100
97
101
Running `wrangler kv key put` will create a new key `test` with a value of `12345` on the local namespace specified via the binding `MY_KV_NAMESPACE` in the [Wrangler configuration file](/workers/wrangler/configuration/). This example command sets the local persistence directory to `worker-local` using `--persist-to`, to ensure that the data is created in the correct location. If `--persist-to` was not set, it would create the data in the `.wrangler` folder.
There may be times you want to develop against remote resources and bindings. To run `wrangler dev` in remote mode, add the `--remote` flag, which will run both your code and resources remotely:
For some products like KV and R2, remote resources used for `wrangler dev --remote` must be specified with preview ID/names in the [Wrangler configuration file](/workers/wrangler/configuration/) such as `preview_id` for KV or `preview_bucket name` for R2. Resources used for remote mode (preview) can be different from resources used for production to prevent changing production data during development. To use production data in `wrangler dev --remote`, set the preview ID/name of the resource to the ID/name of your production resource.
0 commit comments