vite-plugins icon indicating copy to clipboard operation
vite-plugins copied to clipboard

feat(dev-server): add `getConnInfo` helper function

Open Hill-98 opened this issue 10 months ago • 4 comments

Fix #251

Hill-98 avatar Apr 02 '25 15:04 Hill-98

🦋 Changeset detected

Latest commit: 1621e9fa2af408e922c9c3566e8e31155ce86a26

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@hono/vite-dev-server Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

changeset-bot[bot] avatar Apr 02 '25 15:04 changeset-bot[bot]

Hi @Hill-98

Thank you for the PR. Ideally, the Node.js Adapter is better to inject incoming and outgoing, though I don't imagine a good implementation now.

yusukebe avatar Apr 24 '25 00:04 yusukebe

Hi @yusukebe

What do you think about this? It adds a helper function so that developers don't have to worry about platform differences.

We can write code like this:

const getConnInfo = import.meta.env.DEV
  ? (await import('@hono/vite-dev-server/conninfo')).getConnInfo
  : (await import('xxxxxx/conninfo')).getConnInfo

Hill-98 avatar Apr 24 '25 07:04 Hill-98

test is updated

Hill-98 avatar Apr 26 '25 17:04 Hill-98

Hi @Hill-98

I'm sorry I'm late.

I want to know how you use getConnInfo for production. This getConnInfo imported from @hono/vite-dev-server/conninfo is unavailable in production.

yusukebe avatar Jun 23 '25 05:06 yusukebe

@yusukebe We can use the import.meta.env.DEV provided by vite to implement dynamic importing and tree shaking.

like this:

const getConnInfo = import.meta.env.DEV
  ? (await import('@hono/vite-dev-server/conninfo')).getConnInfo
  : (await import('xxxxxx/conninfo')).getConnInfo

only vite serve will import @hono/vite-dev-server, vite build will import production packages.

Hill-98 avatar Jun 23 '25 08:06 Hill-98

@Hill-98

I got it, so this PR is meaningful. One thing. Can you add the description for this feature in README.md? Thanks.

yusukebe avatar Jun 23 '25 21:06 yusukebe

@yusukebe I added a simple description to README.md, what do you think?

Hill-98 avatar Jun 24 '25 15:06 Hill-98

@Hill-98

Thanks! Looks good to me. I'll merge and release a new version.

yusukebe avatar Jun 24 '25 23:06 yusukebe