@cloudflare/vite-plugin 0.0.0-29f2076a6 → 0.0.0-2b37abe10

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 CHANGED
@@ -16,13 +16,32 @@ 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
+
19
38
  ### Install the dependencies
20
39
 
21
40
  ```sh
22
- npm install @cloudflare/vite-plugin wrangler --save-dev
41
+ npm install vite @cloudflare/vite-plugin wrangler --save-dev
23
42
  ```
24
43
 
25
- ### Add the plugin to your Vite config
44
+ ### Create your Vite config file and include the Cloudflare plugin
26
45
 
27
46
  ```ts
28
47
  // vite.config.ts
@@ -40,7 +59,7 @@ export default defineConfig({
40
59
  ```toml
41
60
  # wrangler.toml
42
61
 
43
- name = "my-worker"
62
+ name = "cloudflare-vite-quick-start"
44
63
  compatibility_date = "2024-12-30"
45
64
  main = "./src/index.ts"
46
65
  ```
@@ -57,7 +76,7 @@ export default {
57
76
  };
58
77
  ```
59
78
 
60
- You can now develop (`vite dev`), build (`vite build`), preview (`vite preview`), and deploy (`wrangler deploy`) your application.
79
+ You can now develop (`npm run dev`), build (`npm run build`), preview (`npm run preview`), and deploy (`npm exec wrangler deploy`) your application.
61
80
 
62
81
  ## Tutorial
63
82
 
@@ -121,6 +140,15 @@ The `directory` in the output configuration will automatically point to the clie
121
140
  > This output file is a snapshot of your configuration at the time of the build and is modified to reference your build artifacts.
122
141
  > It is the configuration that is used for preview and deployment.
123
142
 
143
+ #### Update the .gitignore file
144
+
145
+ Wrangler will use and/or generate temporary files that should not be stored in git. Add the following lines to the `.gitignore` file:
146
+
147
+ ```gitignore
148
+ .wrangler
149
+ .dev.vars
150
+ ```
151
+
124
152
  #### Run the development server
125
153
 
126
154
  Run `npm run dev` to verify that your application is working as expected.
@@ -447,6 +475,13 @@ The value of `MY_VAR` will therefore be `'Production var'`.
447
475
  If you run `vite build --mode staging` then the 'staging' Vite mode will be used and the 'staging' Cloudflare environment will be selected.
448
476
  The value of `MY_VAR` will therefore be `'Staging var'`.
449
477
 
478
+ ## Secrets
479
+
480
+ Secrets can be provided to your Worker in local development using a [`.dev.vars`](https://developers.cloudflare.com/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`.
481
+
482
+ > [!NOTE]
483
+ > 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.
484
+
450
485
  ## Migrating from `wrangler dev`
451
486
 
452
487
  Migrating from `wrangler dev` is a simple process and you can follow the instructions in the [Quick start](#quick-start) to get started.