@cloudflare/vite-plugin 0.0.0-e5ebdb143 → 0.0.0-f6cc0293d
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +34 -53
- package/dist/index.d.ts +0 -7
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# `@cloudflare/vite-plugin`
|
|
2
2
|
|
|
3
|
-
[Intro](#intro) | [Quick start](#quick-start) | [Tutorial](#tutorial) | [API](#api) | [Cloudflare environments](#
|
|
3
|
+
[Intro](#intro) | [Quick start](#quick-start) | [Tutorial](#tutorial) | [API](#api) | [Cloudflare environments](#worker-environments) | [Migrating from `wrangler dev`](#migrating-from-wrangler-dev)
|
|
4
4
|
|
|
5
5
|
## Intro
|
|
6
6
|
|
|
@@ -16,42 +16,23 @@ Your Worker code runs inside [workerd](https://github.com/cloudflare/workerd), m
|
|
|
16
16
|
|
|
17
17
|
## Quick start
|
|
18
18
|
|
|
19
|
-
### Start with a basic `package.json`
|
|
20
|
-
|
|
21
|
-
```json
|
|
22
|
-
{
|
|
23
|
-
"name": "cloudflare-vite-quick-start",
|
|
24
|
-
"private": true,
|
|
25
|
-
"version": "0.0.0",
|
|
26
|
-
"type": "module",
|
|
27
|
-
"scripts": {
|
|
28
|
-
"dev": "vite",
|
|
29
|
-
"build": "vite build",
|
|
30
|
-
"preview": "vite preview"
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
> [!NOTE]
|
|
36
|
-
> Ensure that you include `"type": "module"` in order to use ES modules by default.
|
|
37
|
-
|
|
38
19
|
### Install the dependencies
|
|
39
20
|
|
|
40
21
|
```sh
|
|
41
|
-
npm install
|
|
22
|
+
npm install @cloudflare/vite-plugin wrangler --save-dev
|
|
42
23
|
```
|
|
43
24
|
|
|
44
|
-
###
|
|
25
|
+
### Add the plugin to your Vite config
|
|
45
26
|
|
|
46
27
|
```ts
|
|
47
28
|
// vite.config.ts
|
|
48
29
|
|
|
49
|
-
import { defineConfig } from
|
|
50
|
-
import { cloudflare } from
|
|
30
|
+
import { defineConfig } from 'vite'
|
|
31
|
+
import { cloudflare } from '@cloudflare/vite-plugin'
|
|
51
32
|
|
|
52
33
|
export default defineConfig({
|
|
53
34
|
plugins: [cloudflare()],
|
|
54
|
-
})
|
|
35
|
+
})
|
|
55
36
|
```
|
|
56
37
|
|
|
57
38
|
### Create your Worker config file
|
|
@@ -59,7 +40,7 @@ export default defineConfig({
|
|
|
59
40
|
```toml
|
|
60
41
|
# wrangler.toml
|
|
61
42
|
|
|
62
|
-
name = "
|
|
43
|
+
name = "my-worker"
|
|
63
44
|
compatibility_date = "2024-12-30"
|
|
64
45
|
main = "./src/index.ts"
|
|
65
46
|
```
|
|
@@ -71,12 +52,12 @@ main = "./src/index.ts"
|
|
|
71
52
|
|
|
72
53
|
export default {
|
|
73
54
|
fetch() {
|
|
74
|
-
return new Response(`Running in ${navigator.userAgent}!`)
|
|
55
|
+
return new Response(`Running in ${navigator.userAgent}!`)
|
|
75
56
|
},
|
|
76
|
-
}
|
|
57
|
+
}
|
|
77
58
|
```
|
|
78
59
|
|
|
79
|
-
You can now develop (`
|
|
60
|
+
You can now develop (`vite dev`), build (`vite build`), preview (`vite preview`), and deploy (`wrangler deploy`) your application.
|
|
80
61
|
|
|
81
62
|
## Tutorial
|
|
82
63
|
|
|
@@ -107,13 +88,13 @@ npm install @cloudflare/vite-plugin wrangler --save-dev
|
|
|
107
88
|
```ts
|
|
108
89
|
// vite.config.ts
|
|
109
90
|
|
|
110
|
-
import { defineConfig } from
|
|
111
|
-
import react from
|
|
112
|
-
import { cloudflare } from
|
|
91
|
+
import { defineConfig } from 'vite'
|
|
92
|
+
import react from '@vitejs/plugin-react'
|
|
93
|
+
import { cloudflare } from '@cloudflare/vite-plugin'
|
|
113
94
|
|
|
114
95
|
export default defineConfig({
|
|
115
96
|
plugins: [react(), cloudflare()],
|
|
116
|
-
})
|
|
97
|
+
})
|
|
117
98
|
```
|
|
118
99
|
|
|
119
100
|
#### Create your Worker config file
|
|
@@ -200,22 +181,22 @@ The assets `binding` defined here will allow you to access the assets functional
|
|
|
200
181
|
// api/index.ts
|
|
201
182
|
|
|
202
183
|
interface Env {
|
|
203
|
-
ASSETS: Fetcher
|
|
184
|
+
ASSETS: Fetcher
|
|
204
185
|
}
|
|
205
186
|
|
|
206
187
|
export default {
|
|
207
188
|
fetch(request, env) {
|
|
208
|
-
const url = new URL(request.url)
|
|
189
|
+
const url = new URL(request.url)
|
|
209
190
|
|
|
210
|
-
if (url.pathname.startsWith(
|
|
191
|
+
if (url.pathname.startsWith('/api/')) {
|
|
211
192
|
return Response.json({
|
|
212
|
-
name:
|
|
213
|
-
})
|
|
193
|
+
name: 'Cloudflare',
|
|
194
|
+
})
|
|
214
195
|
}
|
|
215
196
|
|
|
216
|
-
return env.ASSETS.fetch(request)
|
|
197
|
+
return env.ASSETS.fetch(request)
|
|
217
198
|
},
|
|
218
|
-
} satisfies ExportedHandler<Env
|
|
199
|
+
} satisfies ExportedHandler<Env>
|
|
219
200
|
```
|
|
220
201
|
|
|
221
202
|
The Worker above will be invoked for any request not matching a static asset.
|
|
@@ -230,14 +211,14 @@ Replace the file contents with the following code:
|
|
|
230
211
|
```tsx
|
|
231
212
|
// src/App.tsx
|
|
232
213
|
|
|
233
|
-
import { useState } from
|
|
234
|
-
import reactLogo from
|
|
235
|
-
import viteLogo from
|
|
236
|
-
import
|
|
214
|
+
import { useState } from 'react'
|
|
215
|
+
import reactLogo from './assets/react.svg'
|
|
216
|
+
import viteLogo from '/vite.svg'
|
|
217
|
+
import './App.css'
|
|
237
218
|
|
|
238
219
|
function App() {
|
|
239
|
-
const [count, setCount] = useState(0)
|
|
240
|
-
const [name, setName] = useState(
|
|
220
|
+
const [count, setCount] = useState(0)
|
|
221
|
+
const [name, setName] = useState('unknown')
|
|
241
222
|
|
|
242
223
|
return (
|
|
243
224
|
<>
|
|
@@ -264,9 +245,9 @@ function App() {
|
|
|
264
245
|
<div className="card">
|
|
265
246
|
<button
|
|
266
247
|
onClick={() => {
|
|
267
|
-
fetch(
|
|
248
|
+
fetch('/api/')
|
|
268
249
|
.then((res) => res.json() as Promise<{ name: string }>)
|
|
269
|
-
.then((data) => setName(data.name))
|
|
250
|
+
.then((data) => setName(data.name))
|
|
270
251
|
}}
|
|
271
252
|
aria-label="get name"
|
|
272
253
|
>
|
|
@@ -280,10 +261,10 @@ function App() {
|
|
|
280
261
|
Click on the Vite and React logos to learn more
|
|
281
262
|
</p>
|
|
282
263
|
</>
|
|
283
|
-
)
|
|
264
|
+
)
|
|
284
265
|
}
|
|
285
266
|
|
|
286
|
-
export default App
|
|
267
|
+
export default App
|
|
287
268
|
```
|
|
288
269
|
|
|
289
270
|
Now, if you click the button, it will display 'Name from API is: Cloudflare'.
|
|
@@ -329,12 +310,12 @@ The `cloudflare` plugin should be included in the Vite `plugins` array:
|
|
|
329
310
|
```ts
|
|
330
311
|
// vite.config.ts
|
|
331
312
|
|
|
332
|
-
import { defineConfig } from
|
|
333
|
-
import { cloudflare } from
|
|
313
|
+
import { defineConfig } from 'vite'
|
|
314
|
+
import { cloudflare } from '@cloudflare/vite-plugin'
|
|
334
315
|
|
|
335
316
|
export default defineConfig({
|
|
336
317
|
plugins: [cloudflare()],
|
|
337
|
-
})
|
|
318
|
+
})
|
|
338
319
|
```
|
|
339
320
|
|
|
340
321
|
It accepts an optional `PluginConfig` parameter.
|
package/dist/index.d.ts
CHANGED
|
@@ -19,13 +19,6 @@ interface PluginConfig extends EntryWorkerConfig {
|
|
|
19
19
|
persistState?: PersistState;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
/**
|
|
23
|
-
* Vite plugin that enables a full-featured integration between Vite and the Cloudflare Workers runtime.
|
|
24
|
-
*
|
|
25
|
-
* See the [README](https://github.com/cloudflare/workers-sdk/tree/main/packages/vite-plugin-cloudflare#readme) for more details.
|
|
26
|
-
*
|
|
27
|
-
* @param pluginConfig An optional {@link PluginConfig} object.
|
|
28
|
-
*/
|
|
29
22
|
declare function cloudflare(pluginConfig?: PluginConfig): vite.Plugin;
|
|
30
23
|
|
|
31
24
|
export { cloudflare };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudflare/vite-plugin",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-f6cc0293d",
|
|
4
4
|
"description": "Cloudflare plugin for Vite",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloudflare",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"@hattip/adapter-node": "^0.0.49",
|
|
37
37
|
"unenv": "npm:unenv-nightly@2.0.0-20241218-183400-5d6aec3",
|
|
38
38
|
"ws": "^8.18.0",
|
|
39
|
-
"miniflare": "0.0.0-
|
|
39
|
+
"miniflare": "0.0.0-f6cc0293d"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@cloudflare/workers-types": "^4.20241230.0",
|
|
@@ -47,12 +47,12 @@
|
|
|
47
47
|
"typescript": "^5.7.2",
|
|
48
48
|
"vite": "^6.0.7",
|
|
49
49
|
"@cloudflare/workers-tsconfig": "0.0.0",
|
|
50
|
-
"@cloudflare/workers-shared": "0.0.0-
|
|
51
|
-
"wrangler": "0.0.0-
|
|
50
|
+
"@cloudflare/workers-shared": "0.0.0-f6cc0293d",
|
|
51
|
+
"wrangler": "0.0.0-f6cc0293d"
|
|
52
52
|
},
|
|
53
53
|
"peerDependencies": {
|
|
54
54
|
"vite": "^6.0.7",
|
|
55
|
-
"wrangler": "^
|
|
55
|
+
"wrangler": "^0.0.0-f6cc0293d"
|
|
56
56
|
},
|
|
57
57
|
"publishConfig": {
|
|
58
58
|
"access": "public"
|