Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
@sveltejs/adapter-cloudflare-workers
Advanced tools
SvelteKit adapter that creates a Cloudflare Workers site using a function for dynamic server rendering.
SvelteKit adapter that creates a Cloudflare Workers site using a function for dynamic server rendering.
Requires Wrangler v2. Wrangler v1 is no longer supported.
Comparisons
adapter-cloudflare
– supports all SvelteKit features; builds for
Cloudflare Pagesadapter-cloudflare-workers
– supports all SvelteKit features; builds for
Cloudflare Workersadapter-static
– only produces client-side static assets; compatible with
Cloudflare PagesNote: Cloudflare Pages' new Workers integration is currently in beta.
Compared toadapter-cloudflare-workers
,adapter-cloudflare
is the preferred approach for most users since building on top of Pages unlocks automatic builds and deploys, preview deployments, instant rollbacks, etc.
From SvelteKit's perspective, there is no difference and no functionality loss when migrating to/from the Workers and the Pages adapters.
Install with npm i -D @sveltejs/adapter-cloudflare-workers
, then add the adapter to your svelte.config.js
:
import adapter from '@sveltejs/adapter-cloudflare-workers';
export default {
kit: {
adapter: adapter()
}
};
This adapter expects to find a wrangler.toml file in the project root. It should look something like this:
name = "<your-service-name>"
account_id = "<your-account-id>"
main = "./.cloudflare/worker.js"
site.bucket = "./.cloudflare/public"
build.command = "npm run build"
compatibility_date = "2021-11-12"
workers_dev = true
<your-service-name>
can be anything. <your-account-id>
can be found by logging into your Cloudflare dashboard and grabbing it from the end of the URL:
https://dash.cloudflare.com/<your-account-id>
It's recommended that you add the
.cloudflare
directory (or whichever directories you specified formain
andsite.bucket
) to your.gitignore
.
You will need to install wrangler and log in, if you haven't already:
npm i -g wrangler
wrangler login
Then, you can build your app and deploy it:
wrangler publish
The env
object, containing KV/DO namespaces etc, is passed to SvelteKit via the platform
property along with context
and caches
, meaning you can access it in hooks and endpoints:
export async function post({ request, platform }) {
const x = platform.env.YOUR_DURABLE_OBJECT_NAMESPACE.idFromName('x');
}
To make these types available to your app, reference them in your src/app.d.ts
:
/// <reference types="@sveltejs/kit" />
+/// <reference types="@sveltejs/adapter-cloudflare-workers" />
declare namespace App {
interface Platform {
+ env?: {
+ YOUR_KV_NAMESPACE: KVNamespace;
+ YOUR_DURABLE_OBJECT_NAMESPACE: DurableObjectNamespace;
+ };
}
}
platform.env
is only available in the production build. Use wrangler to test it locally
FAQs
SvelteKit adapter that creates a Cloudflare Workers site using a function for dynamic server rendering
The npm package @sveltejs/adapter-cloudflare-workers receives a total of 828 weekly downloads. As such, @sveltejs/adapter-cloudflare-workers popularity was classified as not popular.
We found that @sveltejs/adapter-cloudflare-workers demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.