WranglerJson
The WranglerJson resource generates a wrangler.json
configuration file for a Cloudflare Worker. This file is used by the Wrangler CLI to deploy and manage Workers.
Minimal Example
Section titled “Minimal Example”Creates a basic wrangler.json file for a Worker:
import { Worker, WranglerJson } from "alchemy/cloudflare";
const worker = await Worker("api", { name: "api-worker", entrypoint: "./src/index.ts",});
await WranglerJson("wrangler", { worker,});
With Custom Path
Section titled “With Custom Path”Specify a custom path for the wrangler.json file:
await WranglerJson("wrangler", { worker, path: "./config/wrangler.dev.json",});
With Bindings
Section titled “With Bindings”Generate wrangler.json with Worker bindings:
const kv = await KVNamespace("cache", { title: "cache-store",});
const queue = await Queue("tasks", { name: "task-queue",});
const worker = await Worker("api", { name: "api-worker", entrypoint: "./src/index.ts", bindings: { CACHE: kv, TASKS: queue, },});
await WranglerJson("wrangler", { worker,});
With Cron Triggers
Section titled “With Cron Triggers”If the Worker has scheduled crons, they are written to wrangler.json
under the
triggers
field:
const worker = await Worker("cron", { name: "cron-worker", entrypoint: "./src/cron.ts", crons: ["*/3 * * * *", "0 15 1 * *", "59 23 LW * *"],});
await WranglerJson("wrangler", { worker });
With Transform Hook
Section titled “With Transform Hook”The transform hook allows you to customize the wrangler.json configuration. For example, adding a custom environment variable:
await WranglerJson("my-app", { transform: { wrangler: (spec) => ({ ...spec, vars: { ...spec.vars, CUSTOM_VAR: "value", }, }), },});