-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
feat(adapters): Add back adapter.esbuild to allow configuration of bundling step #9398
feat(adapters): Add back adapter.esbuild to allow configuration of bundling step #9398
Conversation
@benmccann has mentioned previously that esbuild is considered an implementation detail. However, I personally think it's unlikely that we would move from esbuild here, and if we do it should probably be a breaking change regardless of if we added esbuild specific options because of how different the two are. A perspective against this would be the unnecessary complexity in a lot of cases, and an increase in the ability to accidentally break your build. At the end of the day I am generally for this change as the adapters default settings can't cover every weird situation people seem to get themself into. We should see what other maintainers think about merging this before reviewing in case it's decided that we want to be more generic with the options |
Thanks @ghostdevv. I might agree with you. I wanted to represent Rich in the discussion though. His point of view is that the underlying issue should be addressed rather than working around it. E.g. in #10521 the user wants to stub out APIs, but a nicer solution would be to update the
@tomaspietravallo Are you using an old version of the adapter? We temporarily set it to |
I think we can fix quite a few of the issues (good example #10544). However, there will still be edge cases - for example for the first time ever I had to use an esbuild plugin with the cloudflare adapter, the only way I could do that was by installing this pr's code changes |
@benmccann well this PR is somewhat old (Mar 10th), but I was using the latest version of the adapter at that point in time. It does seem to be set to This was just a test on my personal website so I ended up giving up on this, but ideally I would've been able to set I am still open to working on this issue and pushing a way to modify esbuild settings as an advanced feature. I fully agree with you #10521 (comment) in that this would be a nice option to have for unmaintained projects and the like, but should strongly be advised against (I'm glad ghostdevv found my code useful but I wouldn't recommend anyone try it out on production) |
@tomaspietravallo We decided to go ahead with exposing esbuild options. Are you able to continue this PR? The merge conflicts need to be resolved, and the new options would need some documentation updates. |
I am. Things are ramping up at work and I'm pretty busy lately but I'll do my best to make progress on this PR |
Evan just announced that they will be replacing esbuild in Vite and are aiming to do so by the end of the year: https://viteconf.org/23/replay/vite_keynote. I think we would also end up replacing esbuild with rolldown in order to minimize the number of dependencies in projects. Given that we may soon be removing esbuild, I'm not sure we should be exposing the esbuild options right now |
esbuild is great for the "chuck everything in a single file with lazy closures" case that we use in the adapters, which Rollup currently doesn't do, and I don't think Rolldown will either if it maintains parity with Rollup. I think we'll be on esbuild for a while. |
If you jump to the end of Evan's keynote you can see that his plan is to make rolldown a replacement for esbuild in the first of four stages. It's not until later on in stage two that they plan to start replacing rollup with it. So at the beginning it will actually be more of a replacement for esbuild than rollup as far as I understand |
Compatible Node built-ins are now supported in Cloudflare deployments, thanks to #10544. I've just opened #11675 which does the same thing for edge functions on Netlify and Vercel. As @benmccann says upthread, my view is that this is far preferable to exposing the |
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm test
and lint the project withpnpm lint
andpnpm check
Changesets
pnpm changeset
and following the prompts. Changesets that add features should beminor
and those that fix bugs should bepatch
. Please prefix changeset messages withfeat:
,fix:
, orchore:
.Hey there! I am opening this PR to solve my own issue.
The problem:
Essentially the lack of configuration prevents us from modifying key configuration of the bundling step which cannot be accessed in any other way. Related issues/ PRs: #3733 #1914
In my particular case:
platform: neutral
prevents certain modules that require node modules from bundling as edge functions (in particular@google-cloud/storage
but I heavily suspect many other packages may have the same issue #3733). I cannot find any workarounds to get the packages to bundle other than modifying the adapter (be it hard coding or creating a configurable one)It appears from #1914 this was a feature at one point but has silently been dropped. If there is a reason for this to be the case, I would be glad to hear.
This PR’s proposed solution
This PR adds an argument
esbuild
of typefunction
which gets called inside the adapter with the default options as only parameter. I adhered to what’s described in the adapters’ (older) read mes as much as possible.Changes:
This PR does not change the default
platform
nor should have any effect on projects that do not pass the esbuild argument to the adapter in theirsvelte.config.js
filesThis PR does affect sites that pass an
esbuild
argument to the adapter in their configs. It takes the output ofesbuild
and uses it in place of the default optionsI am not fully aware platforms other than Netlify would support
platform: node
but I still believe being able to access this and other key configuration options foresbuild
should be permitted as a power-feature.Packages affected:
adapter-netlify
adapter-vercel
adapter-cloudflare
Thank you for considering this PR, and thank you to all maintainers for the hard work you put in, Svelte/Kit is awesome!