Skip to content

Commit

Permalink
fix(cloudflare-pages): add apply option (#146)
Browse files Browse the repository at this point in the history
* fix(cloudflare-pages): add `apply` option

* add changeset
  • Loading branch information
yusukebe authored Jun 16, 2024
1 parent 21af833 commit 0547664
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/fresh-ears-leave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@hono/vite-cloudflare-pages': patch
---

fix: add `apply` option
10 changes: 9 additions & 1 deletion packages/cloudflare-pages/src/cloudflare-pages.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { builtinModules } from 'module'
import { readdir, writeFile } from 'node:fs/promises'
import { resolve } from 'node:path'
import type { Plugin, UserConfig, ResolvedConfig } from 'vite'
import type { ConfigEnv, Plugin, ResolvedConfig, UserConfig } from 'vite'
import { getEntryContent } from './entry.js'

type CloudflarePagesOptions = {
Expand All @@ -19,6 +19,7 @@ type CloudflarePagesOptions = {
*/
minify?: boolean
emptyOutDir?: boolean
apply?: ((this: void, config: UserConfig, env: ConfigEnv) => boolean) | undefined
}

export const defaultOptions: Required<Omit<CloudflarePagesOptions, 'serveStaticDir'>> = {
Expand All @@ -27,6 +28,12 @@ export const defaultOptions: Required<Omit<CloudflarePagesOptions, 'serveStaticD
external: [],
minify: true,
emptyOutDir: false,
apply: (_config, { command, mode }) => {
if (command === 'build' && mode !== 'client') {
return true
}
return false
},
}

const WORKER_JS_NAME = '_worker.js'
Expand Down Expand Up @@ -92,6 +99,7 @@ export const cloudflarePagesPlugin = (options?: CloudflarePagesOptions): Plugin
await writeFile(path, JSON.stringify(staticRoutes))
}
},
apply: options?.apply ?? defaultOptions.apply,
config: async (): Promise<UserConfig> => {
return {
ssr: {
Expand Down

0 comments on commit 0547664

Please sign in to comment.