Skip to content

Commit 3457b4e

Browse files
committed
PCX review
1 parent 19a8a91 commit 3457b4e

File tree

11 files changed

+89
-93
lines changed

11 files changed

+89
-93
lines changed

src/content/docs/workers/vite-plugin/get-started.mdx

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
---
22
pcx_content_type: get-started
33
title: Get started
4-
head: []
54
sidebar:
65
order: 1
76
description: Get started with the Vite plugin
@@ -14,9 +13,9 @@ This guide demonstrates creating a standalone Worker from scratch.
1413
{/* Add link to React Router framework guide */}If you would instead like to create a new application from a ready-to-go template, refer to the [React](/workers/frameworks/framework-guides/react/) or [Vue](/workers/frameworks/framework-guides/vue/) framework guides.
1514
:::
1615

17-
### Start with a basic `package.json`
16+
## Start with a basic `package.json`
1817

19-
```json
18+
```json title="package.json"
2019
{
2120
"name": "cloudflare-vite-quick-start",
2221
"private": true,
@@ -35,15 +34,13 @@ This guide demonstrates creating a standalone Worker from scratch.
3534
Ensure that you include `"type": "module"` in order to use ES modules by default.
3635
:::
3736

38-
### Install the dependencies
37+
## Install the dependencies
3938

4039
<PackageManagers type="add" pkg="vite @cloudflare/vite-plugin wrangler" dev />
4140

42-
### Create your Vite config file and include the Cloudflare plugin
43-
44-
```ts
45-
// vite.config.ts
41+
## Create your Vite config file and include the Cloudflare plugin
4642

43+
```ts title="vite.config.ts"
4744
import { defineConfig } from "vite";
4845
import { cloudflare } from "@cloudflare/vite-plugin";
4946

@@ -54,9 +51,9 @@ export default defineConfig({
5451

5552
The Cloudflare Vite plugin doesn't require any configuration by default and will look for a `wrangler.jsonc`, `wrangler.json` or `wrangler.toml` in the root of your application.
5653

57-
Refer to the [API reference](/workers/vite-plugin/api/) for configuration options.
54+
Refer to the [API reference](/workers/vite-plugin/reference/api/) for configuration options.
5855

59-
### Create your Worker config file
56+
## Create your Worker config file
6057

6158
<WranglerConfig>
6259

@@ -69,16 +66,14 @@ main = "./src/index.ts"
6966
</WranglerConfig>
7067

7168
The `name` field specifies the name of your Worker.
72-
By default, this is also used as the name of the Worker's Vite Environment (see [Vite Environments](/workers/vite-plugin/vite-environments/) for more information).
69+
By default, this is also used as the name of the Worker's Vite Environment (see [Vite Environments](/workers/vite-plugin/reference/vite-environments/) for more information).
7370
The `main` field specifies the entry file for your Worker code.
7471

7572
For more information about the Worker configuration, see [Configuration](/workers/wrangler/configuration/).
7673

77-
### Create your Worker entry file
78-
79-
```ts
80-
// src/index.ts
74+
## Create your Worker entry file
8175

76+
```ts title="src/index.ts"
8277
export default {
8378
fetch() {
8479
return new Response(`Running in ${navigator.userAgent}!`);
@@ -88,6 +83,6 @@ export default {
8883

8984
A request to this Worker will return 'Running in Cloudflare-Workers!', demonstrating that the code is running inside the Workers runtime.
9085

91-
### Dev, build, preview and deploy
86+
## Dev, build, preview and deploy
9287

9388
You can now start the Vite development server (`npm run dev`), build the application (`npm run build`), preview the built application (`npm run preview`), and deploy to Cloudflare (`npm run deploy`).

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ pcx_content_type: overview
33
title: Vite plugin
44
sidebar:
55
order: 16
6-
head: []
76
description: A full-featured integration between Vite and the Workers runtime
87
---
98

src/content/docs/workers/vite-plugin/api.mdx renamed to src/content/docs/workers/vite-plugin/reference/api.mdx

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
---
22
pcx_content_type: reference
33
title: API
4-
head: []
54
sidebar:
65
order: 3
76
description: Vite plugin API
87
---
98

10-
### `cloudflare()`
9+
## `cloudflare()`
1110

1211
The `cloudflare` plugin should be included in the Vite `plugins` array:
1312

14-
```ts {4, 7}
15-
// vite.config.ts
16-
13+
```ts {4, 7} title="vite.config.ts"
1714
import { defineConfig } from "vite";
1815
import { cloudflare } from "@cloudflare/vite-plugin";
1916

@@ -24,7 +21,7 @@ export default defineConfig({
2421

2522
It accepts an optional `PluginConfig` parameter.
2623

27-
### `interface PluginConfig`
24+
## `interface PluginConfig`
2825

2926
- `configPath?: string`
3027

@@ -40,7 +37,7 @@ It accepts an optional `PluginConfig` parameter.
4037
Setting the name here will override this.
4138
A typical use case is setting `viteEnvironment: { name: "ssr" }` to apply the Worker to the SSR environment.
4239

43-
See [Vite Environments](/workers/vite-plugin/vite-environments/) for more information.
40+
See [Vite Environments](/workers/vite-plugin/reference/vite-environments/) for more information.
4441

4542
- `persistState?: boolean | { path: string }`
4643

@@ -54,7 +51,7 @@ It accepts an optional `PluginConfig` parameter.
5451
By default, the debugging inspector is enabled and listens on port `9229`.
5552
A custom port can be provided or, alternatively, setting this to `false` will disable the debugging inspector.
5653

57-
See [Debugging](/workers/vite-plugin/debugging/) for more information.
54+
See [Debugging](/workers/vite-plugin/reference/debugging/) for more information.
5855

5956
- `auxiliaryWorkers?: Array<AuxiliaryWorkerConfig>`
6057

@@ -70,7 +67,7 @@ If using multiple Workers, each auxiliary Worker must be deployed individually.
7067
You can inspect the `dist` directory and then run `wrangler deploy -c dist/<auxiliary-worker>/wrangler.json` for each.
7168
:::
7269

73-
### `interface AuxiliaryWorkerConfig`
70+
## `interface AuxiliaryWorkerConfig`
7471

7572
- `configPath: string`
7673

@@ -84,4 +81,4 @@ You can inspect the `dist` directory and then run `wrangler deploy -c dist/<auxi
8481
By default, the environment name is the Worker name with `-` characters replaced with `_`.
8582
Setting the name here will override this.
8683

87-
See [Vite Environments](/workers/vite-plugin/vite-environments/) for more information.
84+
See [Vite Environments](/workers/vite-plugin/reference/vite-environments/) for more information.

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
---
22
pcx_content_type: reference
33
title: Cloudflare Environments
4-
head: []
54
sidebar:
65
order: 9
76
description: Using Cloudflare environments with the Vite plugin
@@ -48,7 +47,7 @@ This flattened configuration combines [top-level only](/workers/wrangler/configu
4847
:::note
4948
The default Vite environment name for a Worker is always the top-level Worker name.
5049
This enables you to reference the Worker consistently in your Vite config when using multiple Cloudflare environments.
51-
See [Vite Environments](/workers/vite-plugin/vite-environments/) for more information.
50+
See [Vite Environments](/workers/vite-plugin/reference/vite-environments/) for more information.
5251
:::
5352

5453
Cloudflare environments can also be used in development.
@@ -60,7 +59,7 @@ Running `vite dev` or `vite build` without providing `CLOUDFLARE_ENV` will use t
6059
As Cloudflare environments are applied at dev and build time, specifying `CLOUDFLARE_ENV` when running `vite preview` or `wrangler deploy` will have no effect.
6160
:::
6261

63-
### Combining Cloudflare environments and Vite modes
62+
## Combining Cloudflare environments and Vite modes
6463

6564
You may wish to combine the concepts of [Cloudflare environments](/workers/wrangler/environments/) and [Vite modes](https://vite.dev/guide/env-and-mode.html#modes).
6665
With this approach, the Vite mode can be used to select the Cloudflare environment and a single method can be used to determine environment specific configuration and code.

src/content/docs/workers/vite-plugin/debugging.mdx renamed to src/content/docs/workers/vite-plugin/reference/debugging.mdx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
---
22
pcx_content_type: reference
33
title: Debugging
4-
head: []
54
sidebar:
65
order: 5
76
description: Debugging with the Vite plugin
87
---
98

109
The Cloudflare Vite plugin has debugging enabled by default and listens on port `9229`.
11-
You may choose a custom port or disable debugging by setting the `inspectorPort` option in the [plugin config](/workers/vite-plugin/api#interface-pluginconfig).
10+
You may choose a custom port or disable debugging by setting the `inspectorPort` option in the [plugin config](/workers/vite-plugin/reference/api#interface-pluginconfig).
1211
There are two recommended methods for debugging your Workers during local development:
1312

14-
### DevTools
13+
## DevTools
1514

1615
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).
1716
Navigating to this route will open a DevTools tab for each of the Workers in your application.
@@ -22,11 +21,11 @@ Once the tab(s) are open, you can make a request to your application and start d
2221
When debugging multiple Workers, you may need to allow your browser to open pop-ups.
2322
:::
2423

25-
### VS Code
24+
## VS Code
2625

2726
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:
2827

29-
```json
28+
```json title=".vscode/launch.json"
3029
{
3130
"configurations": [
3231
{
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
pcx_content_type: navigation
3+
title: Reference
4+
sidebar:
5+
order: 5
6+
group:
7+
hideIndex: true
8+
---
9+
10+
import { DirectoryListing } from "~/components";
11+
12+
<DirectoryListing />
Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
---
22
pcx_content_type: reference
33
title: Migrating from wrangler dev
4-
head: []
54
sidebar:
65
order: 6
76
description: Migrating from wrangler dev to the Vite plugin
@@ -10,26 +9,26 @@ description: Migrating from wrangler dev to the Vite plugin
109
In most cases, migrating from [`wrangler dev`](/workers/wrangler/commands/#dev) is straightforward and you can follow the instructions in [Get started](/workers/vite-plugin/get-started/).
1110
There are a few key differences to highlight:
1211

13-
### Input and output Worker config files
12+
## Input and output Worker config files
1413

1514
With the Cloudflare Vite plugin, your [Worker config file](/workers/wrangler/configuration/) (for example, `wrangler.jsonc`) is the input configuration and a separate output configuration is created as part of the build.
1615
This output file is a snapshot of your configuration at the time of the build and is modified to reference your build artifacts.
1716
It is the configuration that is used for preview and deployment.
1817
Once you have run `vite build`, running `wrangler deploy` or `vite preview` will automatically locate this output configuration file.
1918

20-
### Cloudflare Environments
19+
## Cloudflare Environments
2120

22-
With the Cloudflare Vite plugin, [Cloudflare Environments](/workers/vite-plugin/cloudflare-environments/) are applied at dev and build time.
21+
With the Cloudflare Vite plugin, [Cloudflare Environments](/workers/vite-plugin/reference/cloudflare-environments/) are applied at dev and build time.
2322
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`.
2423

25-
### Redundant fields in the Wrangler config file
24+
## Redundant fields in the Wrangler config file
2625

2726
There are various options in the [Worker config file](/workers/wrangler/configuration/) that are ignored when using Vite, as they are either no longer applicable or are replaced by Vite equivalents.
2827
If these options are provided, then warnings will be printed to the console with suggestions for how to proceed.
2928
Examples where the Vite configuration should be used instead include `alias` and `define`.
30-
See [Vite Environments](/workers/vite-plugin/vite-environments/) for more information about configuring your Worker environments in Vite.
29+
See [Vite Environments](/workers/vite-plugin/reference/vite-environments/) for more information about configuring your Worker environments in Vite.
3130

32-
### No remote mode
31+
## No remote mode
3332

3433
The Vite plugin does not support [remote mode](/workers/local-development/#develop-using-remote-resources-and-bindings).
3534
We will be adding support for accessing remote resources in local development in a future update.

src/content/docs/workers/vite-plugin/secrets.mdx renamed to src/content/docs/workers/vite-plugin/reference/secrets.mdx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
---
22
pcx_content_type: reference
33
title: Secrets
4-
head: []
54
sidebar:
65
order: 7
76
description: Using secrets with the Vite plugin
@@ -13,7 +12,7 @@ import { PackageManagers, WranglerConfig } from "~/components";
1312
For deployed Workers, they are set via the dashboard or Wrangler CLI.
1413

1514
In local development, secrets can be provided to your Worker by using a [`.dev.vars`](/workers/configuration/secrets/#local-development-with-secrets) file.
16-
If you are using [Cloudflare Environments](/workers/vite-plugin/cloudflare-environments/) then the relevant `.dev.vars` file will be selected.
15+
If you are using [Cloudflare Environments](/workers/vite-plugin/reference/cloudflare-environments/) then the relevant `.dev.vars` file will be selected.
1716
For example, `CLOUDFLARE_ENV=staging vite dev` will load `.dev.vars.staging` if it exists and fall back to `.dev.vars`.
1817

1918
:::note

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
---
22
pcx_content_type: reference
33
title: Static Assets
4-
head: []
54
sidebar:
65
order: 4
76
description: Static assets and the Vite plugin

src/content/docs/workers/vite-plugin/vite-environments.mdx renamed to src/content/docs/workers/vite-plugin/reference/vite-environments.mdx

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
---
22
pcx_content_type: reference
33
title: Vite Environments
4-
head: []
54
sidebar:
65
order: 8
76
description: Vite environments and the Vite plugin
@@ -12,7 +11,7 @@ import { WranglerConfig } from "~/components";
1211
The [Vite Environment API](https://vite.dev/guide/api-environment), released in Vite 6, is the key feature that enables the Cloudflare Vite plugin to integrate Vite directly with the Workers runtime.
1312
It is not necessary to understand all the intricacies of the Environment API as an end user, but it is useful to have a high-level understanding.
1413

15-
### Default behavior
14+
## Default behavior
1615

1716
Vite creates two environments by default: `client` and `ssr`.
1817
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.
@@ -23,10 +22,10 @@ This name can be used to reference the environment in your Vite config in order
2322

2423
:::note
2524
The default Vite environment name for a Worker is always the top-level Worker name.
26-
This enables you to reference the Worker consistently in your Vite config when using multiple [Cloudflare Environments](/workers/vite-plugin/cloudflare-environments/).
25+
This enables you to reference the Worker consistently in your Vite config when using multiple [Cloudflare Environments](/workers/vite-plugin/reference/cloudflare-environments/).
2726
:::
2827

29-
### Environment configuration
28+
## Environment configuration
3029

3130
In the following example we have a Worker named `my-worker` that is associated with a Vite environment named `my_worker`.
3231
We use the Vite config to set global constant replacements for this environment:
@@ -41,9 +40,7 @@ main = "./src/index.ts"
4140

4241
</WranglerConfig>
4342

44-
```ts
45-
// vite.config.ts
46-
43+
```ts title="vite.config.ts"
4744
import { defineConfig } from "vite";
4845
import { cloudflare } from "@cloudflare/vite-plugin";
4946

@@ -61,16 +58,14 @@ export default defineConfig({
6158

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

64-
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](/workers/vite-plugin/api/#interface-pluginconfig) that is accessed via service bindings.
61+
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](/workers/vite-plugin/reference/api/#interface-pluginconfig) that is accessed via service bindings.
6562

66-
### React Router v7
63+
## React Router v7
6764

6865
If you are using the Cloudflare Vite plugin with [React Router v7](https://reactrouter.com/), then your Worker is used for server-side rendering and tightly integrated with the framework.
6966
To support this, you should assign it to the `ssr` environment by setting `viteEnvironment.name` in the plugin config.
7067

71-
```ts
72-
// vite.config.ts
73-
68+
```ts title="vite.config.ts"
7469
import { defineConfig } from "vite";
7570
import { cloudflare } from "@cloudflare/vite-plugin";
7671
import { reactRouter } from "@react-router/dev/vite";

0 commit comments

Comments
 (0)