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
update wrangler config docs to include vite plugin (#21137)
* aliasing as example
* note when not applicable to vite plugin
* fixups
* revert notice about upload_source_maps
* shorten asset routing summary
* some assets updates
* update links and env notes
* Apply suggestions from code review
* update routing summary
* Update src/content/docs/workers/static-assets/index.mdx
Co-authored-by: James Opstad <[email protected]>
* Apply suggestions from code review
Co-authored-by: James Opstad <[email protected]>
---------
Co-authored-by: James Opstad <[email protected]>
Copy file name to clipboardExpand all lines: src/content/docs/workers/static-assets/index.mdx
+4Lines changed: 4 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -59,6 +59,10 @@ The **assets directory** specified in your [Wrangler configuration file](/worker
59
59
60
60
</WranglerConfig>
61
61
62
+
:::note
63
+
If you are using the [Cloudflare Vite plugin](/workers/vite-plugin/), you do not need to specify `assets.directory`. For more information about using static assets with the Vite plugin, refer to the [plugin documentation](/workers/vite-plugin/reference/static-assets/).
64
+
:::
65
+
62
66
By adding an [**assets binding**](/workers/static-assets/binding/#binding), you can directly fetch and serve assets within your Worker code.
Copy file name to clipboardExpand all lines: src/content/docs/workers/wrangler/commands.mdx
+4Lines changed: 4 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -515,6 +515,7 @@ None of the options for this command are required. Also, many can be set in your
515
515
- Skip Wrangler's build steps. Particularly useful when using custom builds. Refer to [Bundling](https://developers.cloudflare.com/workers/wrangler/bundling/) for more information.
- An ordered list of rules that define which modules to import, and what type to import them as. You will need to specify rules to use `Text`, `Data` and `CompiledWasm` modules, or when you wish to have a `.js` file be treated as an `ESModule` instead of `CommonJS`.
144
+
- Not applicable if you're using the [Cloudflare Vite plugin](/workers/vite-plugin/).
- The directory in which module "rules" should be evaluated when including additional files (via `find_additional_modules`) into a Worker deployment. Defaults to the directory containing the `main` entry point of the Worker if not specified.
167
+
- Not applicable if you're using the [Cloudflare Vite plugin](/workers/vite-plugin/).
- If you're using the [Cloudflare Vite plugin](/workers/vite-plugin/), `minify` is replaced by Vite's [`build.minify`](https://vite.dev/config/build-options.html#build-minify).
- A map of values to substitute when deploying your Worker.
206
+
- If you're using the [Cloudflare Vite plugin](/workers/vite-plugin/), `define` is replaced by Vite's [`define`](https://vite.dev/config/shared-options.html#define).
Wrangler bundling is not applicable if you're using the [Cloudflare Vite plugin](/workers/vite-plugin/).
1042
+
:::
1043
+
1023
1044
Wrangler can operate in two modes: the default bundling mode and `--no-bundle` mode.
1024
1045
In bundling mode, Wrangler will traverse all the imports of your code and generate a single JavaScript "entry-point" file.
1025
1046
Imported source code is "inlined/bundled" into this entry-point file.
@@ -1077,6 +1098,10 @@ See https://developers.cloudflare.com/workers/wrangler/bundling/ for more detail
1077
1098
1078
1099
## Local development settings
1079
1100
1101
+
:::note
1102
+
If you're using the [Cloudflare Vite plugin](/workers/vite-plugin/), you should use Vite's [server options]](https://vite.dev/config/server-options.html) instead.
1103
+
:::
1104
+
1080
1105
You can configure various aspects of local development, such as the local protocol or port.
If you're using the [Cloudflare Vite plugin](/workers/vite-plugin/), `alias` is replaced Vite's [`resolve.alias`](https://vite.dev/config/shared-options.html#resolve-alias).
1150
+
:::
1151
+
1123
1152
You can configure Wrangler to replace all calls to import a particular package with a module of your choice, by configuring the `alias` field:
1124
1153
1125
1154
<WranglerConfig>
@@ -1280,6 +1309,8 @@ This section describes a feature that can be implemented by frameworks and other
1280
1309
1281
1310
It is unlikely that an application developer will need to use this feature, but it is documented here to help you understand when Wrangler is using a generated configuration rather than the original, user's configuration.
1282
1311
1312
+
For example, when using the [Cloudflare Vite plugin](/workers/vite-plugin/), an output Worker configuration file is generated as part of the build. This is then used for preview and deployment.
1313
+
1283
1314
:::
1284
1315
1285
1316
Some framework tools, or custom pre-build processes, generate a modified Wrangler configuration to be used to deploy the Worker code.
Wrangler allows you to use environments to create different configurations for the same Worker application. Environments are configured in the Worker's [Wrangler configuration file](/workers/wrangler/configuration/).
11
-
There is a default (top-level) environment and you can create named environments that provide environment-specific configuration.
11
+
12
+
When you create an environment, Cloudflare effectively creates a new Worker with the name `<top-level-name>-<environment-name>`. For example, a Worker project named `my-worker` with an environment `dev` would deploy as a Worker named `my-worker-dev`.
12
13
13
14
Review the following environments flow:
14
15
16
+
<Steps>
15
17
1. Create a Worker, named `my-worker` for example.
16
18
2. Create an environment, for example `dev`, in the Worker's [Wrangler configuration file](/workers/wrangler/configuration/), by adding a `[env.<ENV_NAME>]` section.
17
19
18
-
<WranglerConfig>
20
+
<WranglerConfig>
19
21
20
-
```json
21
-
{
22
-
"name": "my-worker",
23
-
"env": {
24
-
"<ENV_NAME>": {
25
-
// environment-specific configuration goes here
26
-
}
27
-
}
28
-
}
29
-
```
22
+
```json
23
+
{
24
+
"name": "my-worker",
25
+
"env": {
26
+
"<ENV_NAME>": {
27
+
// environment-specific configuration goes here
28
+
}
29
+
}
30
+
}
31
+
```
32
+
</WranglerConfig>
30
33
31
-
</WranglerConfig>
34
+
3. You can configure the `dev` environment with different values to the top-level environment. Refer [here](/workers/wrangler/configuration/#environments) for how different options are inherited - or not inherited - between environments.
35
+
For example, to set a different route for a Worker in the `dev` environment:
32
36
33
-
3. You can configure the `dev` environment with different values to the top-level environment. Refer [here](/workers/wrangler/configuration/#environments) for how different options are inherited - or not inherited - between environments.
37
+
<WranglerConfig>
34
38
35
-
For example, to set a different route for a Worker in the `dev` environment:
39
+
```toml
40
+
name = "your-worker"
41
+
route = "example.com"
36
42
37
-
<WranglerConfig>
43
+
[env.dev]
44
+
route = "dev.example.com"
45
+
```
38
46
39
-
```toml
40
-
name = "your-worker"
41
-
route = "example.com"
47
+
</WranglerConfig>
42
48
43
-
[env.dev]
44
-
route = "dev.example.com"
45
-
```
49
+
4. Environments are used with the `--env` or `-e` flag on Wrangler commands. For example, you can develop the Worker in the `dev` environment by running `npx wrangler dev -e=dev`, and deploy it with `npx wrangler deploy -e=dev`.
46
50
47
-
</WranglerConfig>
48
-
4. Environments are used with the `--env` or `-e` flag on Wrangler commands. For example, you can develop the Worker in the `dev` environment by running `npx wrangler dev -e=dev`, and deploy it with `npx wrangler deploy -e=dev`.
51
+
<Renderfile="vite-environments" />
49
52
50
-
:::note
51
-
52
-
Cloudflare effectively creates a new Worker for you when you create a Worker with an environment. Wrangler appends the environment name to the top-level name. For example, a Worker project named `my-worker` with an environment `dev` would deploy a Worker named `my-worker-dev`. You must use this name when referencing a Worker in a particular environment, for example in a [service binding](/workers/wrangler/configuration/#service-bindings).
If you're using the [Cloudflare Vite plugin](/workers/vite-plugin/), you select the environment at dev or build time via the `CLOUDFLARE_ENV` environment variable rather than the `--env` flag. Otherwise, environments are defined in your Worker config file as usual. For more detail on using environments with the Cloudflare Vite plugin, refer to the [plugin documentation](/workers/vite-plugin/reference/cloudflare-environments/).
Copy file name to clipboardExpand all lines: src/content/partials/workers/workers-assets-routing-summary.mdx
+2-8Lines changed: 2 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,12 +2,6 @@
2
2
{}
3
3
---
4
4
5
-
When using Workers Assets, Cloudflare will first attempt to serve any static assets which match the incoming request.
5
+
By default, Cloudflare first tries to match a request path against a static asset path, which is based on the file structure of the uploaded asset directory. This is either the directory specified by `assets.directory` in your Wrangler config or, in the case of the [Cloudflare Vite plugin](/workers/vite-plugin/), the output directory of the client build. Failing that, we invoke a Worker if one is present. If there is no Worker, or the Worker then uses the asset binding, Cloudflare will fallback to the behaviour set by [`not_found_handling`](/workers/static-assets/routing/#not_found_handling).
6
6
7
-
For example, if you have requests for `/logo.png` and `/blog/hello-world.html` in your assets directory, and make requests for `/logo.png` and `/blog/hello-world`, those files will be served respectively. The [`html_handling`](/workers/static-assets/routing/#html_handling) option allows you to customize the serving of HTML files if you have specific needs around redirects and trailing slashes.
8
-
9
-
If a request does not match a static asset, Cloudflare will then invoke your Worker script module, if one is present. This can be configured with the [`main`](/workers/wrangler/configuration/#inheritable-keys) property in the [Wrangler configuration file](/workers/wrangler/configuration/).
10
-
11
-
Finally, if a request does not match any static assets, and either a Worker script module is not present, or from within that Worker script module, the [asset binding](/workers/static-assets/binding/)'s `fetch` method is called (e.g. `env.ASSETS.fetch(request)`), Cloudflare will fall back to evaluating the [`not_found_handling`](/workers/static-assets/routing/#not_found_handling) behavior. By default, it will serve a null-body 404-status response, but this can be configured to instead serve custom HTML 404 pages, or to serve a single-page application (SPA).
12
-
13
-
At present, there is no way to customize this routing behavior beyond the `html_handling` and `not_found_handling` options. We plan to offer additional configuration controls, such as allowing you to always run the Worker script modules for certain paths, in the future.
7
+
Refer to the [routing documentation](/workers/static-assets/routing/#routing-configuration) for more information about how routing works with static assets, and how to customize this behavior.
You should use [Workers Static Assets](/workers/static-assets/) to host full-stack applications instead of Workers Sites. Do not use Workers Sites for new projects.
7
+
You should use [Workers Static Assets](/workers/static-assets/) to host full-stack applications instead of Workers Sites. It has been deprecated in Wrangler v4, and the [Cloudflare Vite plugin](/workers/vite-plugin/) does not support Workers Sites. Do not use Workers Sites for new projects.
0 commit comments