@oselvar/sveltekit-add-worker-exports 2.2.0 → 2.2.1
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 +10 -0
- package/dist/index.js +8 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -116,6 +116,16 @@ A handy shortcut is to add a `preview` script to `package.json`:
|
|
|
116
116
|
|
|
117
117
|
> Note: `vite preview` is *not* suitable here — it only serves static assets and cannot run Durable Objects. Always use `wrangler dev` to preview the production worker.
|
|
118
118
|
|
|
119
|
+
### Wrangler environments
|
|
120
|
+
|
|
121
|
+
Set `CLOUDFLARE_ENV` to run dev against one of the `env` blocks in your wrangler config:
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
CLOUDFLARE_ENV=staging pnpm dev
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
The sidecar then behaves like `wrangler dev --env staging`: it uses `env.staging`'s bindings and `vars`, loads `.env.staging` / `.env.staging.local` (or `.dev.vars.staging`) on top of `.env` / `.env.local`, and registers as `<name>-dev-worker-staging`. As with wrangler, values in `.env` files override `vars`.
|
|
128
|
+
|
|
119
129
|
## Scheduled, queue, email, tail handlers
|
|
120
130
|
|
|
121
131
|
Cloudflare invokes non-fetch handlers (`scheduled`, `queue`, `email`, `tail`, `trace`) as methods on the worker's default export, not as named exports. Put them on the `default` export of your entry point and the plugin merges them onto the production worker's default alongside SvelteKit's fetch handler:
|
package/dist/index.js
CHANGED
|
@@ -417,6 +417,14 @@ function devPlugins(options) {
|
|
|
417
417
|
await removeDeadRegistryEntry(registryPath, registeredSidecarName);
|
|
418
418
|
worker = await unstable_startWorker({
|
|
419
419
|
config: tempConfigPath,
|
|
420
|
+
// Wrangler falls back to CLOUDFLARE_ENV when resolving the
|
|
421
|
+
// config (and the sidecar's name), but not when choosing which
|
|
422
|
+
// `.env` / `.dev.vars` files to load: without `env`, only `.env`
|
|
423
|
+
// and `.env.local` are read, and they override the env's `vars`.
|
|
424
|
+
// Passing it adds `.env.<env>` / `.dev.vars.<env>`, matching
|
|
425
|
+
// `wrangler dev --env <env>`. See
|
|
426
|
+
// https://github.com/oselvar/sveltekit-add-worker-exports/issues/11
|
|
427
|
+
env: process.env.CLOUDFLARE_ENV,
|
|
420
428
|
// `testScheduled` mounts a `/__scheduled` endpoint on the sidecar
|
|
421
429
|
// so cron handlers can be invoked manually in dev — wrangler dev
|
|
422
430
|
// never auto-fires crons. Curl
|
package/package.json
CHANGED