Skip to content

Commit

Permalink
docs(readme): update readme (#97)
Browse files Browse the repository at this point in the history
* docs(readme): update readme

* remove `.`
  • Loading branch information
yusukebe authored Feb 24, 2024
1 parent 88fe05f commit 52c4652
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 47 deletions.
77 changes: 31 additions & 46 deletions packages/dev-server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,11 @@ export type DevServerOptions = {
export?: string
injectClientScript?: boolean
exclude?: (string | RegExp)[]
env?: Env | EnvFunc
plugins?: Plugin[]
ignoreWatching?: (string | RegExp)[]
adapter?: {
env?: Env
onServerClose?: () => Promise<void>
}
}
```
Expand All @@ -121,7 +124,7 @@ export const defaultOptions: Required<Omit<DevServerOptions, 'cf'>> = {
/^\/static\/.+/,
/^\/node_modules\/.*/,
],
plugins: [],
ignoreWatching: [/\/\.wrangler/],
}
```

Expand All @@ -148,60 +151,42 @@ export default defineConfig({
})
```

### `env`
### `ignoreWatching`

You can pass `ENV` variables to your application by setting the `env` option.
`ENV` values can be accessed using `c.env` in your Hono application.
You can add target directories for the server to watch.

### `plugins`
### `adapter`

There are plugins for each platform to set up their own environment, etc.
You can pass the `env` value of a specified environment to the application.

## Plugins
## Adapter

### Cloudflare Pages
### Cloudflare

You can use Cloudflare Pages plugin, which allow you to access bindings such as variables, KV, D1, and others.
You can pass the Bindings specified in `wrangler.toml` to your application by using Wrangler's `getPlatformProxy()` function.

```ts
import pages from '@hono/vite-dev-server/cloudflare-pages'

export default defineConfig({
plugins: [
devServer({
plugins: [
pages({
bindings: {
NAME: 'Hono',
},
kvNamespaces: ['MY_KV'],
}),
],
}),
],
import devServer from '@hono/vite-dev-server'
import { defineConfig } from 'vite'
import { getPlatformProxy } from 'wrangler'

export default defineConfig(async () => {
const { env, dispose } = await getPlatformProxy()
return {
plugins: [
devServer({
adapter: {
env,
onServerClose: dispose,
},
}),
],
}
})
```

These Bindings are emulated by Miniflare in the local.

#### 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({
plugins: [
pages({
d1Databases: ['DB'],
d1Persist: true,
}),
],
}),
],
})
```
> [!NOTE]
> The `wrangler.toml` is not used in the Cloudflate Pages production environment. Please configure Bindings from the dashboard.
## Client-side

Expand Down
2 changes: 1 addition & 1 deletion packages/dev-server/e2e/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { defineConfig } from 'vite'
import { getPlatformProxy } from 'wrangler'
import devServer, { defaultOptions } from '../src'
import pages from '../src/cloudflare-pages'
import { getPlatformProxy } from 'wrangler'

export default defineConfig(async () => {
const { env, dispose } = await getPlatformProxy()
Expand Down

0 comments on commit 52c4652

Please sign in to comment.