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

Deployment instructions to local server missing, either with node and bun #42

Open
Angelelz opened this issue Feb 12, 2024 · 11 comments
Open

Comments

@Angelelz
Copy link

It looks like for now honox only supports building for cloudflare. I looked into the codebase and couldn't find a vite plugin to build for node or bun. Or at least instructions.

@laiso
Copy link
Contributor

laiso commented Feb 20, 2024

I think it would be better to do this in Vite-build layer. For reference, I wrote a simple Vite plugin, so could someone please try it?

https://gist.github.com/laiso/caa8f8ea18451763b70c9c8af9815230

@Angelelz
Copy link
Author

I think it would be better to do this in Vite-build layer. For reference, I wrote a simple Vite plugin, so could someone please try it?

https://gist.github.com/laiso/caa8f8ea18451763b70c9c8af9815230

I had abandoned the idea of using honox because I'm not well versed in vite plugin development and didn't have the time to investigate and make it myself. I just tried the plugin in your gist and it work flawlessly!
It would be great if this could be included in the honox codebase but this workaround is doing wonders! You sir are a absolute magician! Thank you.

@yusukebe
Copy link
Member

Thanks @laiso

It would be great if this could be included in the honox codebase but this workaround is doing wonders!

We could create a package like @hono/vite-build-node, but the gist code would have to be more customized.

@laiso
Copy link
Contributor

laiso commented Mar 22, 2024

We could create a package like @hono/vite-build-node, but the gist code would have to be more customized.

If there are users who need it, I will open a pull request. Thanks

@andresgutgon
Copy link

Hi @laiso awesome resource your vite node config. I almost has it running but the assets are not working. You can see the repo here:
latitude-dev/static-embedding-examples@86d0e29#diff-abafdaf60d09c6581d544ea9cf2e0e1581bae831d56de39071d4d60fd908f217R22

Any idea of what could be wrong?

@laiso
Copy link
Contributor

laiso commented Mar 27, 2024

@andresgutgon Your project's assets are located under static/assets/, so you'll need to reference them accordingly.

-        worker.use('/static/*', serveStatic({ root: './dist' }))
+       worker.use('/static/*', serveStatic({ root: './dist/static' }))

However, we must consider how to enable setting the default configuration in our vite-plugin.

@andresgutgon
Copy link

No but I have JS and CSS in 2 different places

dist/static/styles.css

dist/assets/*.js // compiled islands and runtime

With

worker.use('/static/*', serveStatic({ root: './dist' }))

CSS is loading fine but the *.js files are not being loaded

@laiso
Copy link
Contributor

laiso commented Mar 27, 2024

thanks, I understand your problem, but I haven't figured out how to fix it yet.

@andresgutgon
Copy link

Solved. To make your Vite plugin work I put everything into static folder. By default Rollup put chunk files into assets and statci files into static like the CSS. But Rollup has options to build everything into the same folder:

https://github.com/latitude-dev/static-embedding-examples/blob/main/nodejs/vite.config.ts#L18-L20

So now I can build a Honox and deploy it to fly.io 🎉

Honesty this was harder than expected. But I have to say honox is very nice

@laiso
Copy link
Contributor

laiso commented Apr 1, 2024

Solved. To make your Vite plugin work I put everything into static folder. By default Rollup put chunk files into assets and statci files into static like the CSS. But Rollup has options to build everything into the same folder:

Good 👍 I also tried building it, and it works as expected.
However, ideally, it would be linked to a CSS with a hash like this comment style.css?url for deployments...

@umstek
Copy link

umstek commented Apr 23, 2024

I think it would be better to do this in Vite-build layer. For reference, I wrote a simple Vite plugin, so could someone please try it?

https://gist.github.com/laiso/caa8f8ea18451763b70c9c8af9815230

Above might work with Bun as well but I modified it a little to support Bun, React, and TailwindCSS. Didn't test thoroughly.

https://gist.github.com/umstek/e87b1c2c2e0521fd44c7629e0c889301

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants