Skip to content

Commit

Permalink
fix(cloudflare): add known cloudflare: externals (#2976)
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 authored Jan 7, 2025
1 parent c3ee670 commit 8c8fd75
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions src/presets/cloudflare/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@ import { writeCFPagesFiles, writeCFPagesStaticFiles } from "./utils";

export type { CloudflareOptions as PresetOptions } from "./types";

const cloudflareExternals = [
// https://developers.cloudflare.com/email-routing/email-workers/reply-email-workers/
"cloudflare:email",
// https://developers.cloudflare.com/workers/runtime-apis/tcp-sockets/
"cloudflare:sockets",
// https://developers.cloudflare.com/durable-objects/get-started/walkthrough/
"cloudflare:workers",
// https://developers.cloudflare.com/workflows/build/workers-api/
"cloudflare:workflows",
] as const;

const cloudflarePages = defineNitroPreset(
{
extends: "cloudflare",
Expand All @@ -20,6 +31,9 @@ const cloudflarePages = defineNitroPreset(
publicDir: "{{ output.dir }}/{{ baseURL }}",
serverDir: "{{ output.dir }}/_worker.js",
},
unenv: {
external: [...cloudflareExternals],
},
alias: {
// Hotfix: Cloudflare appends /index.html if mime is not found and things like ico are not in standard lite.js!
// https://github.com/nitrojs/nitro/pull/933
Expand Down Expand Up @@ -86,6 +100,9 @@ const cloudflare = defineNitroPreset(
wasm: {
lazy: true,
},
unenv: {
external: [...cloudflareExternals],
},
hooks: {
async compiled(nitro: Nitro) {
await writeFile(
Expand Down Expand Up @@ -123,6 +140,9 @@ const cloudflareModuleLegacy = defineNitroPreset(
inlineDynamicImports: false,
},
},
unenv: {
external: [...cloudflareExternals],
},
wasm: {
lazy: false,
esmImport: true,
Expand Down Expand Up @@ -156,6 +176,9 @@ const cloudflareModule = defineNitroPreset(
preview: "npx wrangler dev ./server/index.mjs --assets ./public/",
deploy: "npx wrangler deploy",
},
unenv: {
external: [...cloudflareExternals],
},
rollupConfig: {
output: {
format: "esm",
Expand Down Expand Up @@ -191,8 +214,8 @@ const cloudflareDurable = defineNitroPreset(
{
extends: "cloudflare-module",
entry: "./runtime/cloudflare-durable",
rollupConfig: {
external: ["cloudflare:workers"],
unenv: {
external: [...cloudflareExternals],
},
},
{
Expand Down

0 comments on commit 8c8fd75

Please sign in to comment.