Skip to content

Commit 437b56f

Browse files
committed
General improvements
1 parent e7347bb commit 437b56f

File tree

6 files changed

+56
-18
lines changed

6 files changed

+56
-18
lines changed

src/content/docs/workers/vite-plugin/cloudflare-environments.mdx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ vars = { MY_VAR = "Production var" }
3434
If you run `CLOUDFLARE_ENV=production vite build` then the output `wrangler.json` file generated by the build will be a flattened configuration for the 'production' Cloudflare environment.
3535
This combines [top-level only](/workers/wrangler/configuration/#top-level-only-keys), [inheritable](/workers/wrangler/configuration/#inheritable-keys), and [non-inheritable](/workers/wrangler/configuration/#non-inheritable-keys) keys.
3636
The value of `MY_VAR` will therefore be `'Production var'`.
37-
The name of the Worker will be `'my-worker-production'`.
38-
This is because the environment name is automatically appended to the top-level Worker name.
37+
The name of the Worker will be `'my-worker-production'` because the environment name is automatically appended to the top-level Worker name.
3938

4039
:::note
4140
The default Vite environment name for a Worker is always the top-level Worker name.
@@ -48,7 +47,6 @@ It is common to use the default top-level environment as the development environ
4847

4948
:::note
5049
Running `vite dev` or `vite build` without providing `CLOUDFLARE_ENV` will use the default top-level Cloudflare environment.
51-
The value of `MY_VAR` in the example above would therefore be `'Top-level var'`.
5250
As Cloudflare environments are applied at dev and build time, specifying `CLOUDFLARE_ENV` when running `vite preview` or `wrangler deploy` will have no effect.
5351
:::
5452

@@ -98,4 +96,5 @@ Since the `.env.production` file contains `CLOUDFLARE_ENV=production`, the Cloud
9896
The value of `MY_VAR` will therefore be `'Production var'`.
9997
If you run `vite build --mode staging` then the 'staging' Vite mode will be used and the 'staging' Cloudflare environment will be selected.
10098
The value of `MY_VAR` will therefore be `'Staging var'`.
99+
101100
For more information about using `.env` files with Vite, see the [relevant documentation](https://vite.dev/guide/env-and-mode#env-files).

src/content/docs/workers/vite-plugin/debugging.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ There are two recommended methods for debugging your Workers during local develo
1313

1414
### DevTools
1515

16-
When running `vite dev` or `vite preview`, a `/__debug` route is added that provides access to [Cloudflare's implementation](/packages/chrome-devtools-patches) of [Chrome's DevTools](https://developer.chrome.com/docs/devtools/overview).
16+
When running `vite dev` or `vite preview`, a `/__debug` route is added that provides access to [Cloudflare's implementation](https://github.com/cloudflare/workers-sdk/tree/main/packages/chrome-devtools-patches) of [Chrome's DevTools](https://developer.chrome.com/docs/devtools/overview).
1717
Navigating to this route will open a DevTools tab for each of the Workers in your application.
1818

1919
Once the tab(s) are open, you can make a request to your application and start debugging your Worker code.
@@ -24,7 +24,7 @@ When debugging multiple Workers, you may need to allow your browser to open pop-
2424

2525
### VS Code
2626

27-
To set up VS Code to support breakpoint debugging in your application, you should create a `.vscode/launch.json` file that contains the following configuration:
27+
To set up [VS Code](https://code.visualstudio.com/) to support breakpoint debugging in your application, you should create a `.vscode/launch.json` file that contains the following configuration:
2828

2929
```json
3030
{
@@ -54,7 +54,7 @@ Here, `<NAME_OF_WORKER>` indicates the name of the Worker as specified in your W
5454
If you have used the `inspectorPort` option to set a custom port then this should be the value provided in the `websocketaddress` field.
5555

5656
:::note
57-
If you have more than one Worker in your application, you need to add a configuration in the `configurations` field for each and include the configuration name in the `compounds` `configurations` array.
57+
If you have more than one Worker in your application, you should add a configuration in the `configurations` field for each and include the configuration name in the `compounds` `configurations` array.
5858
:::
5959

6060
With this set up, you can run `vite dev` or `vite preview` and then select **Debug Workers** at the top of the **Run & Debug** panel to start debugging.

src/content/docs/workers/vite-plugin/migrating-from-wrangler-dev.mdx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,30 @@ sidebar:
77
description: Migrating from wrangler dev to the Vite plugin
88
---
99

10-
Migrating from `wrangler dev` is a simple process and you can follow the instructions in [Get started](../get-started/).
10+
In most cases, migrating from `wrangler dev` is straightforward and you can follow the instructions in [Get started](../get-started/).
1111
There are a few key differences to highlight:
1212

1313
### Input and output Worker config files
1414

15-
In the Vite integration, your Worker config file (for example, `wrangler.toml`) is the input configuration and a separate output configuration is created as part of the build.
15+
With the Cloudflare Vite plugin, your Worker config file (for example, `wrangler.jsonc`) is the input configuration and a separate output configuration is created as part of the build.
1616
This output file is a snapshot of your configuration at the time of the build and is modified to reference your build artifacts.
1717
It is the configuration that is used for preview and deployment.
18+
Once you have run `vite build`, running `wrangler deploy` will automatically locate this output configuration file.
19+
20+
### Cloudflare Environments
21+
22+
With the Cloudflare Vite plugin, Cloudflare environments are applied at dev and build time.
23+
Running `wrangler deploy --env some-env` is therefore not applicable and the environment to deploy should instead be set by running `CLOUDFLARE_ENV=some-env vite build`.
24+
See [Cloudflare Environments](../cloudflare-environments/) for more information.
1825

1926
### Redundant fields in the Wrangler config file
2027

2128
There are various options in the Worker config file that are ignored when using Vite, as they are either no longer applicable or are replaced by Vite equivalents.
2229
If these options are provided, then warnings will be printed to the console with suggestions for how to proceed.
2330
Examples where the Vite configuration should be used instead include `alias` and `define`.
31+
See [Vite Environments](../vite-environments/) for more information about configuring your Worker environments in Vite.
32+
33+
### Local only data during local development
34+
35+
The Vite plugin does not support [remote mode](/workers/local-development/#develop-using-remote-resources-and-bindings).
36+
We will be adding support for accessing remote resources in local development in the future.

src/content/docs/workers/vite-plugin/secrets.mdx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@ description: Using secrets with the Vite plugin
99

1010
import { PackageManagers, WranglerConfig } from "~/components";
1111

12-
Secrets can be provided to your Worker in local development using a [`.dev.vars`](/workers/configuration/secrets/#local-development-with-secrets) file. If you are using [Cloudflare Environments](../cloudflare-environments) then the relevant `.dev.vars` file will be selected. For example, `CLOUDFLARE_ENV=staging vite dev` will load `.dev.vars.staging` if it exists and fall back to `.dev.vars`.
12+
Secrets can be provided to your Worker in local development using a [`.dev.vars`](/workers/configuration/secrets/#local-development-with-secrets) file.
13+
If you are using [Cloudflare Environments](../cloudflare-environments) then the relevant `.dev.vars` file will be selected.
14+
For example, `CLOUDFLARE_ENV=staging vite dev` will load `.dev.vars.staging` if it exists and fall back to `.dev.vars`.
1315

1416
:::note
15-
The `vite build` command copies the relevant `.dev.vars[.env-name]` file to the output directory. This is only used when running `vite preview` and is not deployed with your Worker.
17+
The `vite build` command copies the relevant `.dev.vars` file to the output directory.
18+
This is only used when running `vite preview` and is not deployed with your Worker.
1619
:::

src/content/docs/workers/vite-plugin/static-assets.mdx

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,36 @@ pcx_content_type: reference
33
title: Static Assets
44
head: []
55
sidebar:
6-
order: 3
6+
order: 4
77
description: Static assets with the Vite plugin
88
---
99

10-
When using the Cloudflare Vite plugin, it is the `client` environment that is deployed as your static assets.
11-
This will typically include files such as static HTML, front-end JavaScript, CSS, images and fonts.
10+
import { WranglerConfig } from "~/components";
11+
12+
When using the Cloudflare Vite plugin, the `client` environment is deployed as your static assets.
13+
This typically includes files such as static HTML, front-end JavaScript, CSS, images and fonts.
14+
For more information about using static assets in Vite, refer to [Static Asset Handling](https://vite.dev/guide/assets).
15+
16+
The Vite plugin does not require that you provide the `assets` field in order to enable assets and instead determines whether assets should be included based on whether the `client` environment has been built.
17+
By default, the `client` environment is built if there is an `index.html` file in the root of your project or if `build.rollupOptions.input` is specified in the Vite config.
1218

1319
On running `vite build`, an output `wrangler.json` configuration file is included as part of the build output.
1420
The `assets.directory` field in this file is automatically populated with the path to your `client` build output.
1521
It is therefore not necessary to provide the `assets.directory` field in your input Worker configuration.
1622

17-
For more information about using static assets in Vite, see [Static Asset Handling](https://vite.dev/guide/assets).
23+
The `assets` configuration should be used, however, if you wish to set [routing configuration](/workers/static-assets/routing/#routing-configuration) or enable the [assets binding](/workers/static-assets/binding/#binding).
24+
The following example configures the `not_found_handling` for a single-page application so that the fallback will always be the root `index.html` file.
25+
26+
<WranglerConfig>
27+
28+
```toml
29+
assets = { not_found_handling = "single-page-application" }
30+
```
31+
32+
</WranglerConfig>
33+
34+
:::note
35+
The Cloudflare Vite plugin does not support [run_worker_first](/workers/static-assets/binding/#run_worker_first).
36+
:::
37+
38+
{/* Add docs for _headers and _redirects */}

src/content/docs/workers/vite-plugin/vite-environments.mdx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ pcx_content_type: reference
33
title: Vite Environments
44
head: []
55
sidebar:
6-
order: 4
6+
order: 3
77
description: Vite environments and the Vite plugin
88
---
99

@@ -15,12 +15,14 @@ It is not necessary to understand all the intricacies of the Environment API as
1515
### Default behavior
1616

1717
Vite creates two environments by default: `client` and `ssr`.
18-
A front-end only application uses just the `client` environment, whereas a full-stack application created with a framework typically uses the `client` environment for front-end code and the `ssr` environment for server-side rendering.
18+
A front-end only application uses the `client` environment, whereas a full-stack application created with a framework typically uses the `client` environment for front-end code and the `ssr` environment for server-side rendering.
1919

2020
By default, when you add a Worker using the Cloudflare Vite plugin, an additional environment is created.
2121
Its name is derived from the Worker name, with any dashes replaced with underscores.
2222
This name can be used to reference the environment in your Vite config in order to apply environment specific configuration.
2323

24+
### Environment configuration
25+
2426
In the following example we have a Worker named `my-worker` that is associated with a Vite environment named `my_worker`.
2527
We use the Vite config to set global constant replacements for this environment:
2628

@@ -54,7 +56,7 @@ export default defineConfig({
5456

5557
For more information about Vite's configuration options, see [Configuring Vite](https://vite.dev/config/).
5658

57-
The default behavior of using the Worker name as the environment name is appropriate when you have a standalone Worker, such as an API that is accessed from your front-end application, or an [auxiliary Worker](../api#interface-pluginconfig) that is accessed via service bindings.
59+
The default behavior of using the Worker name as the environment name is appropriate when you have a standalone Worker, such as an API that is accessed from your front-end application, or an [auxiliary Worker](../api/#interface-pluginconfig) that is accessed via service bindings.
5860

5961
### React Router v7
6062

@@ -73,4 +75,4 @@ export default defineConfig({
7375
});
7476
```
7577

76-
This merges the configuration with the framework's SSR configuration and ensures that the Worker is included as part of the framework's build output.
78+
This merges the Worker's environment configuration with the framework's SSR configuration and ensures that the Worker is included as part of the framework's build output.

0 commit comments

Comments
 (0)