-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: make
vike-cloudflare
a real Vike extension (#37)
BREAKING CHANGE: update vike to `>=0.4.219`
- Loading branch information
Showing
10 changed files
with
69 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
export { config as default }; | ||
|
||
import { pages as plugin, type VikeCloudflarePagesOptions } from "./index"; | ||
import type { Config } from "vike/types"; | ||
|
||
const config = { | ||
name: "vike-cloudflare", | ||
require: { | ||
vike: ">=0.4.219", | ||
}, | ||
vite: { | ||
plugins: [plugin()], | ||
}, | ||
/* TODO/now | ||
prerender: { | ||
value: null, | ||
disableAutoFullBuild: true | ||
}, | ||
*/ | ||
meta: { | ||
server: { env: { config: true }, global: true }, | ||
}, | ||
} satisfies Config; | ||
|
||
declare global { | ||
namespace Vike { | ||
interface Config { | ||
server?: VikeCloudflarePagesOptions["server"]; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,20 @@ import { normalizePath, type Plugin, type ResolvedConfig } from "vite"; | |
import hattipAsset from "../assets/hattip.js?raw"; | ||
import honoAsset from "../assets/hono.js?raw"; | ||
import vikeAsset from "../assets/vike.js?raw"; | ||
import type { Config } from "vike/types"; | ||
|
||
declare module "vite" { | ||
interface UserConfig { | ||
// TODO/now: | ||
// - Re-use declaration merging done by Vike | ||
// - Extend ResolvedConfig ? | ||
vike?: { | ||
global: { | ||
config: Config; | ||
}; | ||
}; | ||
} | ||
} | ||
|
||
const NAME = "vike-cloudflare"; | ||
const WORKER_JS_NAME = "_worker.js"; | ||
|
@@ -36,25 +50,17 @@ function getAsset(kind: SupportedServers | undefined) { | |
} | ||
} | ||
|
||
export const pages = (options?: VikeCloudflarePagesOptions): Plugin[] => { | ||
export const pages = (): any => { | ||
const virtualEntryId = "virtual:vike-cloudflare-entry"; | ||
const virtualServerId = "virtual:vike-cloudflare-server"; | ||
const resolvedVirtualServerId = `\0${virtualServerId}`; | ||
let resolvedConfig: ResolvedConfig; | ||
let shouldPrerender = false; | ||
let options: VikeCloudflarePagesOptions; | ||
|
||
return [ | ||
{ | ||
name: `${NAME}:disableAutoFullBuild`, | ||
// @ts-ignore | ||
config() { | ||
return { | ||
// TODO/next-major-release: remove this and require >[email protected] | ||
vitePluginSsr: { | ||
disableAutoFullBuild: "prerender", | ||
}, | ||
}; | ||
}, | ||
}, | ||
{ | ||
name: NAME, | ||
|
@@ -101,9 +107,8 @@ export const pages = (options?: VikeCloudflarePagesOptions): Plugin[] => { | |
}, | ||
configResolved: async (config) => { | ||
resolvedConfig = config; | ||
// TODO/next-major-release: remove this and require >[email protected] | ||
// biome-ignore lint/suspicious/noExplicitAny: | ||
shouldPrerender = !!(await (config as any).configVikePromise).prerender; | ||
options = { server: config.vike!.global.config.server }; | ||
shouldPrerender = !!config.vike!.global.config.prerender; | ||
}, | ||
options(inputOptions) { | ||
assert( | ||
|
@@ -196,7 +201,7 @@ export default handler; | |
}, | ||
}, | ||
}, | ||
]; | ||
] satisfies Plugin[]; | ||
}; | ||
|
||
async function symlinkOrCopy(target: string, path: string) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters