Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions packages/cloudflare/src/api/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ export type CloudflareOverrides = {
* @default "none"
*/
routePreloadingBehavior?: RoutePreloadingBehavior;

/**
* List of external modules to exclude from the server bundle.
*/
serverExternals?: string[];
};

/**
Expand All @@ -71,6 +76,7 @@ export function defineCloudflareConfig(config: CloudflareOverrides = {}): OpenNe
cachePurge,
enableCacheInterception = false,
routePreloadingBehavior = "none",
serverExternals = [],
} = config;

return {
Expand Down Expand Up @@ -106,6 +112,7 @@ export function defineCloudflareConfig(config: CloudflareOverrides = {}): OpenNe
},
assetResolver: () => assetResolver,
},
serverExternals,
};
}

Expand Down Expand Up @@ -180,6 +187,7 @@ interface OpenNextConfig extends AwsOpenNextConfig {
maxVersionAgeDays?: number;
};
};
serverExternals?: string[];
}

/**
Expand Down
3 changes: 2 additions & 1 deletion packages/cloudflare/src/cli/build/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import logger from "@opennextjs/aws/logger.js";
import type { Unstable_Config } from "wrangler";

import { OpenNextConfig } from "../../api/config.js";
import { BuildOptions } from "../commands/utils.js";
import type { ProjectOptions } from "../project-options.js";
import { bundleServer } from "./bundle-server.js";
import { compileCacheAssetsManifestSqlFile } from "./open-next/compile-cache-assets-manifest.js";
Expand All @@ -29,7 +30,7 @@ import { getVersion } from "./utils/version.js";
* @param projectOpts The options for the project
*/
export async function build(
options: buildHelper.BuildOptions,
options: BuildOptions,
config: OpenNextConfig,
projectOpts: ProjectOptions,
wranglerConfig: Unstable_Config
Expand Down
5 changes: 3 additions & 2 deletions packages/cloudflare/src/cli/build/bundle-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import { readFile, writeFile } from "node:fs/promises";
import path from "node:path";
import { fileURLToPath } from "node:url";

import { type BuildOptions, getPackagePath } from "@opennextjs/aws/build/helper.js";
import { getPackagePath } from "@opennextjs/aws/build/helper.js";
import { ContentUpdater } from "@opennextjs/aws/plugins/content-updater.js";
import { build, type Plugin } from "esbuild";

import { getOpenNextConfig } from "../../api/config.js";
import { BuildOptions } from "../commands/utils.js";
import type { ProjectOptions } from "../project-options.js";
import { patchVercelOgLibrary } from "./patches/ast/patch-vercel-og-library.js";
import { patchWebpackRuntime } from "./patches/ast/webpack-runtime.js";
Expand Down Expand Up @@ -111,7 +112,7 @@ export async function bundleServer(buildOpts: BuildOptions, projectOpts: Project
// Apply updater updates, must be the last plugin
updater.plugin,
] as Plugin[],
external: ["./middleware/handler.mjs"],
external: ["./middleware/handler.mjs", ...buildOpts.config.serverExternals || []],
alias: {
// Workers have `fetch` so the `node-fetch` polyfill is not needed
"next/dist/compiled/node-fetch": path.join(buildOpts.outputDir, "cloudflare-templates/shims/fetch.js"),
Expand Down
7 changes: 6 additions & 1 deletion packages/cloudflare/src/cli/commands/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,14 @@ export function getNormalizedOptions(config: OpenNextConfig, buildDir = nextAppD
const options = normalizeOptions(config, openNextDistDir, buildDir);
logger.setLevel(options.debug ? "debug" : "info");

return options;
return {
...options,
config,
};
}

export type BuildOptions = ReturnType<typeof getNormalizedOptions>;

/**
* Read the Wrangler config.
*
Expand Down