-
-
Notifications
You must be signed in to change notification settings - Fork 355
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
Trying to do transpiled and bundled standalone server #1165
Comments
The example is still not working but it seems to be because of an error about how you resolve the static dir; it should be fixable on the user land. Let me know if you have further questions, and please update the example to make it work so that I can share with others. Keep me updated how it goes. Thanks for opening this ticket. Closing in favor of #562:
|
Many thanks for the fast response @brillout ! I tried the PR and it works (if you've already built the project once). I added a question there about how this solution could be made better. |
Maybe I'll continue the discussion here if you don't mind. I just did some more work trying to resolve the The tricky thing is that we want to bundle the reference to It doesn't quite work yet though and I'd appreciate any help -- it currently fails with this:
|
Actually never mind, I got it to work as of thomasjm/vike-standalone@d9bbe82 ! It's super fragile and weird (uses TBH, unless I'm missing something, it's beyond me why #562 and vitejs/vite#12165 are proposing such complicated solutions to this problem. It seems to me there's no need to bring in |
Simpler solution: https://github.com/brillout/vike-standalone/tree/simpler.
It's more complicated in a dev context. |
Huh? That's a solution for the static assets problem, which I already fixed: thomasjm/vike-standalone@b521db6 The work I was doing above is to resolve the other problem, the one I've been trying to communicate on thomasjm/vike-standalone#1.
Is it though?
|
For the other problem, I'm busy with a high prio ticket; I'll then have a look at it. I will circle back on this. (With dev context I mean without |
Sounds good, thanks! No rush, I'm happy since I have a workaround now.
If you ask me, HMR / auto-reload is a nice-to-have. It's easy to survive without it; the current disclaimer here clearly states what the user has to do. On the other hand, the ability to create a standalone build at all is a must-have, or else it severely limits how you can deploy a Vike app. |
I agree.
…On Sun 8. Oct 2023 at 11:25, Tom McLaughlin ***@***.***> wrote:
Sounds good, thanks! No rush, I'm happy since I have a workaround now.
With dev context I mean without ts-node. E.g. it isn't clear how HMR /
auto-reload can be implemented.
If you ask me, HMR / auto-reload is a nice-to-have. It's easy to survive
without it; the current disclaimer here
<https://github.com/vikejs/vike/blob/ac0bb99f8828d98d88a2525564b90f7c0b9eeabe/examples/graphql-apollo-react/server/index.js#L1-L5>
clearly states what the user has to do.
On the other hand, the ability to create a standalone build *at all* is a
must-have, or else it severely limits how you can deploy a Vike app.
—
Reply to this email directly, view it on GitHub
<#1165 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAHVQRXSZUCH4P6HPRIWJOLX6JWQFAVCNFSM6AAAAAA5VUSGJOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONJRHE3TINZQHA>
.
You are receiving this because you modified the open/close state.Message
ID: ***@***.***>
|
Actually, I'd like to take some time before tackling this ticket because 1. I want to do some research before starting the implementation and 2. I want to release the V1 design (and soft-deprecate the current design) sooner rather than later as it's blocking the official release of Bati and So it's going to take a little while, but I'd be up for working on this right after the V1 design is released (not to be confused with the V1 release). Rough ETA: this month. |
Esbuild usually also works (and it's fast). Any reason you chose ncc over esbuild? |
I would like to use esbuild, but esbuild in itself doesn't handle bundling/copying binaries/assets. (prisma, sharp, argon2, etc...) Initially, I tried not to involve https://github.com/vercel/ncc (uses webpack to bundle) and use https://github.com/vercel/nft (only discovery, no bundle) instead to discover the binaries/assets and copy them to the dist folder, and let vite/rollup handle the rest, setting the ssr.externals and ssr.noExternals options. I had issues with https://github.com/vercel/nft, not working correctly in my pnpm monorepo, so I commented the code. I will try it again later. |
I see. There is also |
I recently built a website with Vike and managed to do standalone client, server and SSR HTML builds with The
But a match-all regexp works perfectly, e.g. Alternatively, if you want to bundle all but |
@dkourilov Good to know, thanks for sharing. It's a bummer Vite doesn't exclude built-ins automatically. |
@brillout Surprisingly, it doesn't work in
With
But it looks like Vike issue now, with new layout and router. I was using old |
@dkourilov PR welcome to update the example. |
Lean, robust, and I guess (very) fast: https://github.com/nitedani/vite-plugin-standalone. (See source code to understand what it does). It's quite a neat idea and we'll likely make it a built-in Vike feature. |
I've tested this approach on my test project and it seems to work very nicely. If we fork processes using Do you guys have ideas or suggestions on how to approach this in these specific cases? I don't need it anymore, but in case I ever do, I figured i'd ask. |
@simplecommerce standalone({ workers: ["./src/worker.js"] }), |
I will try that, thanks a lot! UPDATE It seems to compile the code and add it to the bundle but it doesn't seem to bundle the imports that the worker code has inside. For example, in my code I have:
And in the output code I see
Am I missing something? |
@simplecommerce |
Hmm, I don't think I'm a fan of the I was happy with my workaround which I posted above, which I put in this commit: thomasjm/vike-standalone@3eb35dd. This worked great for building everything with Vike/Vite. However, I recently wanted to upgrade to the Vike v1 API + versions of Vike later than 0.4.149, but the workaround I had before breaks. It seems like there have been some changes with how server auto-importing works, perhaps involving I saw that there was this commit f555646 which claims to make standalone builds easier, but I'm having trouble understanding how :). Any chance we could get an example in the repo |
Update: I've updated my example and gotten it working with a slightly different weird hack: https://github.com/thomasjm/vike-standalone/ I'd love some help understanding why this hack is needed. Once it's fixed I'd be happy to help make this into an official example. |
Esbuild and Rollup are shipped with Vite, and Esbuild is much faster than Rollup for bundling. In the future I imagine we can use Rolldown instead and remove the Esbuild step, making it more similar to your example. In standalone mode, Rollup is still used to bundle your server code(not library imports), and only the imported libraries are bundled with Esbuild in the final step. This is similar to how Vite works in dev for server code (Esbuild is used for dep-optimization in dev). |
The plan is to have it built-in; nitedani already implemented a PR but there are a couple of blockers to merge it (most notably the Vike CLI which is a breaking change). Hopefully we can land the PRs sooner rather than later (I'm currently busy with other high priority tickets). In the meantime, if your company is up for it, you can consider sponsoring (also for getting a priority bump).
👍 If you run into another issue, update the example to be a reproduction and we'll have a look at it. |
Hello, it's been a few months so I thought I'd ask if there's been any progress on making standalone builds a built-in part of Vike. My weird hacks still work, but it's a bit of a pain to keep tweaking them when I update to new versions of Vike or Vite. I'd love to know if there's an ETA for this, or some way to follow along with the progress. Is #1434 the PR to watch? Thanks! |
@thomasjm In case you didn't see it already, have a look at vike-node. It's ready (or correct me if I'm wrong @nitedani) although we want to restructure it a bit. In a nutshell: you can use it (and we recommend you to), but you should expect a breaking change soon. Note We want to wrap @nitedani I'm thinking, one thing that could be nice is to offer different "levels of support":
The user would have the choice, although we'd only advertise |
Description
I would really like to build a server entrypoint that is not only transpiled (as in #562) but also bundled, so that the resulting
dist
folder is completely standalone. I don't want to worry about providing a separatenode_modules
folder in production with dependencies likeexpress
.I filed an issue in vavite about this, but I think it may properly be solved at the Vike level. None of the solutions I could find online have worked, but I've come up with a solution which I think is really close. The demo repo is here:
https://github.com/thomasjm/vike-standalone
The idea is simple: I add an extra entry to
build.rollupOptions.input
pointing at theserver/index_prod.js
file. (For simplicity, I created a separateindex_prod.js
file, which is likeindex.js
but with development stuff removed.) Then I setssr.noExternal
to prevent externalizing just about everything (except Node builtins).At this point, I can build a
dist
folder which containsdist/server/index.mjs
, and just about everything is bundled. The server actually starts up when you run it!The only issue I'm tripping on is related to
@brillout/vite-plugin-import-build
. This is the point where I could really use some help, as it seems the tricks of this plugin aren't working in this scenario. The output is below. Could I trouble you @brillout ?npm run try-standalone
The text was updated successfully, but these errors were encountered: