bundle-cloudflare-worker Command
Note: This command is implemented as part of the
@blognami/cloudflarepackage, which needs to be installed in your project and imported inlib/index.jsfor it to be available. Projects created withgenerate-projectdo not include it. See Deploy to Cloudflare for the whole walk-through.
Interface
The command builds the project as a Cloudflare Worker script in the build/cloudflare-worker directory, and writes a wrangler.toml when the project has none:
npx blognami bundle-cloudflare-workerParameters
No parameters required.
Examples
# Build the Cloudflare Worker
npx blognami bundle-cloudflare-worker
# Build it minified, as a production build
NODE_ENV=production npx blognami bundle-cloudflare-workerDescription
The bundle-cloudflare-worker command builds the project into the files wrangler runs as a Cloudflare Worker:
- Bundling - Bundles the project, its
blognami.config.jsincluded, into one script holding the Cloudflare Worker and its Durable Object, and writes it tobuild/cloudflare-worker/index.js - Static assets - Runs
bundle-static-assets, which writesbuild/static-assets/ - Assets directory - Empties
build/cloudflare-worker-assets/, then fills it with a copy ofbuild/static-assets/and each file-backed view under its full view name, any file path feature flag segment kept - Config - Writes
wrangler.tomlat the project root, only when the project has none
An existing wrangler.toml is never rewritten or merged. Run the command again after each change to the project.
Generated File Structure
build/
├── cloudflare-worker/
│ └── index.js # The Cloudflare Worker script and its Durable Object
├── cloudflare-worker-assets/ # Emptied and filled on each run
│ ├── service_worker.js
│ └── _blognami/
│ └── _shell/
│ ├── window.js
│ ├── window.js.map
│ ├── styles.css
│ └── service_worker.js.map
└── static-assets/ # Written by bundle-static-assets, which the command runs
wrangler.toml # Only when the project has noneThe written wrangler.toml and its bindings are shown in Deploy to Cloudflare.
Related Commands
bundle-static-assets- Builds the shell's static assets; this command runs itlist-commands- Listsbundle-cloudflare-workeronce@blognami/cloudflareis importedgenerate-project- Create the project the Deploy to Cloudflare guide starts from