Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(README) test: bindings and variables from wrangler.toml #83

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,34 @@ You can also deploy it to Cloudflare Pages.
wrangler pages deploy ./dist
```

## Development

### Wrangler Bindings and Variables

If you use a `wrangler.toml` file to declare Bindings (Such as a D1 Database) and Variables , these can be used in your HonoX application during local development (with the `vite` command) with a small change to your vite.config.ts file.

Import the `getPlatformProxy` function from the `wrangler` package and use it to get the environment variables and dispose function. Then, pass the environment variables to your HonoX application devServer configuration.

```ts
// vite.config.ts
import { defineConfig } from 'vite'
import { getPlatformProxy } from 'wrangler'

export default defineConfig(async () => {
const { env, dispose } = await getPlatformProxy()
return {
plugins: [
honox({
devServer: {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this fix made the type correct, it would be easier to specify "env and onServerClose" as one plugin:

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oo, nice. Will update to match :D

env,
plugins: [{ onServerClose: dispose }],
},
}),
],
}
})
```

## Examples

- https://github.com/yusukebe/honox-examples
Expand All @@ -727,3 +755,4 @@ wrangler pages deploy ./dist
## License

MIT