@cloudflare/vite-plugin 0.1.12 → 0.1.14

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
 
@@ -374,6 +374,10 @@ It accepts an optional `PluginConfig` parameter.
374
374
  All requests are routed through your entry Worker.
375
375
  During the build, each Worker is output to a separate subdirectory of `dist`.
376
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
+
377
381
  > [!NOTE]
378
382
  > When running `wrangler deploy`, only your main (entry) Worker will be deployed.
379
383
  > If using multiple Workers, each must be deployed individually.
@@ -482,6 +486,62 @@ Secrets can be provided to your Worker in local development using a [`.dev.vars`
482
486
  > [!NOTE]
483
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.
484
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
+
485
545
  ## Migrating from `wrangler dev`
486
546
 
487
547
  Migrating from `wrangler dev` is a simple process and you can follow the instructions in the [Quick start](#quick-start) to get started.