open-index/open-npm huggingface dataset:
npm package: @recranet/astro-workers-for-platforms-adapter
Description: Custom Astro adapter for Cloudflare Workers for Platforms.
Latest version: 1.2.0

# astro-workers-for-platforms-adapter

Custom Astro adapter for Cloudflare Workers for Platforms.

## How it works

```
Request → Dispatch Worker → User Worker (worker-entry.mjs) → env.ASSETS.fetch()
```

This adapter ensures Astro always emits a worker entry, even for fully static sites. While static assets could be uploaded to R2 and served by the dispatch worker.
Workers for Platforms supports a native Static Assets binding (`env.ASSETS`) that serves files from the edge with per-tenant isolation — no R2 needed.

Running `astro build` produces two outputs: a bundled worker at `dist/server/entry.mjs` and static assets in `dist/client/`. The adapter sets `ssr.noExternal: true` so Vite inlines all dependencies into a single file with no external imports.

Deployment uses the Workers for Platforms asset upload API in three steps: create session, upload asset buckets, then deploy the worker with a completion token.

## Why not `@astrojs/cloudflare`?

The official `@astrojs/cloudflare` adapter cannot be used here because:

- It requires wrangler as a peer dependency (we deploy programmatically via the API, not with wrangler)
- As of Astro 6, it deletes `_worker.js` for fully static sites — Workers for Platforms always needs a worker entry

## Getting started

```bash
npm install @recranet/astro-workers-for-platforms-adapter
```

```js
// astro.config.mjs
import { defineConfig } from 'astro/config';
import astroWorkersForPlatformsAdapter from '@recranet/astro-workers-for-platforms-adapter';

export default defineConfig({
  adapter: astroWorkersForPlatformsAdapter(),
});
```

## References

- [Cloudflare VibeSDK](https://github.com/cloudflare/vibesdk/blob/27b7a9bf9e8fcced21e28f7c97d9134c120614f3/worker/agents/core/codingAgent.ts#L729)