Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
@sveltejs/adapter-cloudflare
Advanced tools
[Adapter](https://kit.svelte.dev/docs/adapters) for building SvelteKit applications on [Cloudflare Pages](https://developers.cloudflare.com/pages/) with [Workers integration](https://developers.cloudflare.com/pages/platform/functions).
Adapter for building SvelteKit applications on Cloudflare Pages with Workers integration.
If you're using adapter-auto, you don't need to install this — it's already included.
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
, this adapter will be 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.
$ npm i --save-dev @sveltejs/adapter-cloudflare
You can include these changes in your svelte.config.js
configuration file:
import adapter from '@sveltejs/adapter-cloudflare';
export default {
kit: {
adapter: adapter()
}
};
Please follow the Get Started Guide for Cloudflare Pages to begin.
When configuring your project settings, you must use the following settings:
npm run build
or svelte-kit build
.svelte-kit/cloudflare
NODE_VERSION
: 16
or 14
Important: You need to add a
NODE_VERSION
environment variable to both the "production" and "preview" environments. You can add this during project setup or later in the Pages project settings. SvelteKit requires Node14.13
or later, so you should use14
or16
as theNODE_VERSION
value.
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" />
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
Functions contained in the /functions
directory at the project's root will not be included in the deployment, which is compiled to a single _worker.js
file. Functions should be implemented as endpoints in your SvelteKit app.
If you want to use _headers
or _redirects
custom config files to modify cloudflare behaviour you should put those configs in the /static
folder of your SvelteKit project.
FAQs
Adapter for building SvelteKit applications on Cloudflare Pages with Workers integration
The npm package @sveltejs/adapter-cloudflare receives a total of 41,559 weekly downloads. As such, @sveltejs/adapter-cloudflare popularity was classified as popular.
We found that @sveltejs/adapter-cloudflare demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 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
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.