@cloudflare/vite-plugin 0.0.0-e7c7235fd → 0.0.0-e9106dfa5

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
@@ -1,6 +1,6 @@
1
1
  # `@cloudflare/vite-plugin`
2
2
 
3
- [Intro](#intro) | [Quick start](#quick-start) | [Tutorial](#tutorial) | [API](#api) | [Cloudflare environments](#cloudflare-environments) | [Migrating from `wrangler dev`](#migrating-from-wrangler-dev)
3
+ [Intro](#intro) | [Quick start](#quick-start) | [Tutorial](#tutorial) | [API](#api) | [Cloudflare environments](#cloudflare-environments) | [Debugging](#debugging) | [Migrating from `wrangler dev`](#migrating-from-wrangler-dev)
4
4
 
5
5
  ## Intro
6
6
 
@@ -140,6 +140,15 @@ The `directory` in the output configuration will automatically point to the clie
140
140
  > This output file is a snapshot of your configuration at the time of the build and is modified to reference your build artifacts.
141
141
  > It is the configuration that is used for preview and deployment.
142
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
+
143
152
  #### Run the development server
144
153
 
145
154
  Run `npm run dev` to verify that your application is working as expected.
@@ -365,6 +374,10 @@ It accepts an optional `PluginConfig` parameter.
365
374
  All requests are routed through your entry Worker.
366
375
  During the build, each Worker is output to a separate subdirectory of `dist`.
367
376
 
377
+ - `inspectorPort?: number | false`
378
+
379
+ Optional inspector port to use for debugging your workers, for more details on debugging see the [devtools section](#devtools). Can be set to `false` to disable the debugging inspector altogether. Defaults to `9229`.
380
+
368
381
  > [!NOTE]
369
382
  > When running `wrangler deploy`, only your main (entry) Worker will be deployed.
370
383
  > If using multiple Workers, each must be deployed individually.
@@ -466,6 +479,69 @@ The value of `MY_VAR` will therefore be `'Production var'`.
466
479
  If you run `vite build --mode staging` then the 'staging' Vite mode will be used and the 'staging' Cloudflare environment will be selected.
467
480
  The value of `MY_VAR` will therefore be `'Staging var'`.
468
481
 
482
+ ## Secrets
483
+
484
+ 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`.
485
+
486
+ > [!NOTE]
487
+ > 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.
488
+
489
+ ## Debugging
490
+
491
+ The Cloudflare Vite plugin allows you to conveniently debug your Worker code during local development.
492
+
493
+ By default the inspector port used by the plugin is `9229`, which can be customized by providing a different port to the plugin's `inspectorPort` option.
494
+
495
+ There are two recommended ways of doing so, which we'll explore in this section.
496
+
497
+ ### Devtools
498
+
499
+ When running `vite dev` or `vite preview` a `/__debug` route in your local server will be made available which gives you access to [Cloudflare's implementation](/packages/chrome-devtools-patches) of [Chrome's DevTools](https://developer.chrome.com/docs/devtools/overview).
500
+
501
+ Navigating to this route will open a devtools tab for each of the workers in your application (Note: in case of multiple workers you might need to allow your browser to open pop-ups).
502
+
503
+ Once the tab or tabs are open, you can make a request to your application and start debugging your workers' code.
504
+
505
+ Note: If you're not interested in debugging all your workers you can close the tabs of the workers you don't want to debug.
506
+
507
+ ### VS Code
508
+
509
+ To setup VS Code for breakpoint debugging for your application, you will need to create a `.vscode/launch.json` file that contains a configuration following this structure:
510
+
511
+ ```json
512
+ {
513
+ "configurations": [
514
+ {
515
+ "name": "<NAME_OF_WORKER>",
516
+ "type": "node",
517
+ "request": "attach",
518
+ "websocketAddress": "ws://localhost:9229/<NAME_OF_WORKER>",
519
+ "resolveSourceMapLocations": null,
520
+ "attachExistingChildren": false,
521
+ "autoAttachChildProcesses": false,
522
+ "sourceMaps": true
523
+ }
524
+ ],
525
+ "compounds": [
526
+ {
527
+ "name": "Debug All Workers",
528
+ "configurations": ["<NAME_OF_WORKER>"],
529
+ "stopAll": true
530
+ }
531
+ ]
532
+ }
533
+ ```
534
+
535
+ Where, `<NAME_OF_WORKER>` indicates the name of your worker as specified in your Wrangler configuration.
536
+
537
+ Note: if you customized your `inspectorPort` you need to use that port in the `websocketAddress` field.
538
+
539
+ If you have more than one worker you need add a configuration in the `configurations` field for each one and then include the configuration name in the `configurations` array in the compound configuration.
540
+
541
+ Once your `launch.json` file is ready, after running `vite dev` or `vite preview` you can select **Debug All Workers** at the top of the **Run & Debug** panel to attach debuggers to all the various Workers. Then you can add breakpoints to your code and start debugging.
542
+
543
+ Note: You can also manually select the configurations to run (e.g. **Debug Worker1**) to filter which workers you want to debug.
544
+
469
545
  ## Migrating from `wrangler dev`
470
546
 
471
547
  Migrating from `wrangler dev` is a simple process and you can follow the instructions in the [Quick start](#quick-start) to get started.