@hono/vite-dev-server
Advanced tools
Comparing version 0.0.8 to 0.0.9
@@ -1,2 +0,2 @@ | ||
import { WorkerOptions } from 'miniflare'; | ||
import { WorkerOptions, MiniflareOptions } from 'miniflare'; | ||
import { Plugin } from 'vite'; | ||
@@ -8,3 +8,3 @@ | ||
exclude?: (string | RegExp)[]; | ||
cf?: Partial<Omit<WorkerOptions, 'name' | 'script' | 'scriptPath' | 'modules' | 'modulesRoot' | 'modulesRules'>>; | ||
cf?: Partial<Omit<WorkerOptions, 'name' | 'script' | 'scriptPath' | 'modules' | 'modulesRoot' | 'modulesRules'> & Pick<MiniflareOptions, 'cachePersist' | 'd1Persist' | 'durableObjectsPersist' | 'kvPersist' | 'r2Persist'>>; | ||
}; | ||
@@ -11,0 +11,0 @@ declare const defaultOptions: Required<Omit<DevServerOptions, 'cf'>>; |
@@ -7,3 +7,3 @@ import { getRequestListener } from "@hono/node-server"; | ||
}; | ||
const nullScript = 'addEventListener("fetch", (event) => event.respondWith(new Response(null, { status: 404 })));'; | ||
const nullScript = "export default { fetch: () => new Response(null, { status: 404 }) };"; | ||
function devServer(options) { | ||
@@ -18,2 +18,3 @@ const entry = options?.entry ?? defaultOptions.entry; | ||
mf = new Miniflare({ | ||
modules: true, | ||
script: nullScript, | ||
@@ -20,0 +21,0 @@ ...options.cf |
{ | ||
"name": "@hono/vite-dev-server", | ||
"description": "Vite dev-server plugin for Hono", | ||
"version": "0.0.8", | ||
"version": "0.0.9", | ||
"types": "dist/index.d.ts", | ||
@@ -6,0 +6,0 @@ "module": "dist/index.js", |
@@ -100,3 +100,3 @@ # @hono/vite-dev-server | ||
```ts | ||
import type { WorkerOptions } from 'miniflare' | ||
import type { MiniflareOptions, WorkerOptions } from 'miniflare' | ||
@@ -110,4 +110,9 @@ export type DevServerOptions = { | ||
WorkerOptions, | ||
// We can ignore these properties: | ||
'name' | 'script' | 'scriptPath' | 'modules' | 'modulesRoot' | 'modulesRules' | ||
> | ||
> & | ||
Pick< | ||
MiniflareOptions, | ||
'cachePersist' | 'd1Persist' | 'durableObjectsPersist' | 'kvPersist' | 'r2Persist' | ||
> | ||
> | ||
@@ -135,2 +140,17 @@ } | ||
If you have static files in `public/static/*` and want to return them, exclude `/static/*` as follows: | ||
```ts | ||
import devServer, { defaultOptions } from '@hono/vite-dev-server' | ||
import { defineConfig } from 'vite' | ||
export default defineConfig({ | ||
plugins: [ | ||
devServer({ | ||
exclude: ['^/static/.*', ...defaultOptions.exclude], | ||
}), | ||
], | ||
}) | ||
``` | ||
## Cloudflare Bindings | ||
@@ -158,2 +178,19 @@ | ||
### D1 | ||
When using D1, your app will read `.mf/d1/DB/db.sqlite` which is generated automatically with the following configuration: | ||
```ts | ||
export default defineConfig({ | ||
plugins: [ | ||
devServer({ | ||
cf: { | ||
d1Databases: ['DB'], | ||
d1Persist: true, | ||
}, | ||
}), | ||
], | ||
}) | ||
``` | ||
## Notes | ||
@@ -163,3 +200,3 @@ | ||
`@hono/vite-dev-server` depends on `miniflare` for certain platforms you may want to run on. For example, if you want to run your applications on Node.js, the `miniflare` is not needed. However, it's necessary for Cloudflare Workers/Pages, which are important platforms for Hono. And `miniflare` is needed just for development; it will not be bundled for production. We allow including `miniflare` in `@hono/vite-dev-server`. | ||
`@hono/vite-dev-server` depends on `miniflare` for certain platforms you may want to run on. For example, if you want to run your applications on Node.js, the `miniflare` is not needed. However, it's necessary for Cloudflare Workers/Pages, which are important platforms for Hono. And `miniflare` is needed just for development; it will not be bundled for production. | ||
@@ -166,0 +203,0 @@ ### `cf` option with Bun |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9504
93
209