ProjectEvergreen / greenwood

Greenwood is your workbench for the web, embracing web standards from the ground up to empower your stack from front to back.
https://www.greenwoodjs.io
MIT License
96 stars 9 forks source link

single file bundles (SFBs) for SSR page and API routes #1118

Closed thescientist13 closed 5 months ago

thescientist13 commented 1 year ago

Summary

Coming out of the PR for #1088 wanted to track an issue around the output of the bundle files created for SSR page and API route bundles. It would be nice to make sure all these files are as self contained as possible to not have to rely on any particular bundling setups for different hosting providers.

In particular this applies to SSR pages, as currently two output files are generated

Another (potential) complication / urgency for this has been observed in https://github.com/thescientist13/greenwood-demo-adapter-vercel-lit/issues/3 where in now our page output bundling is not consistent, because we have to do hacky things like this. 😬

In general there should be a way to collapse down a lot of these files into one. πŸ™

Details

One particular callout on this is that WCC take a URL for renderToString as the entry point, which means at least one file has to exist on disk I guess, meaning there will always be an entry point and then the actual userland code?

In addition this would also mean making sure Rollup doesn't create chunks.

edit: also, coming out #1122 and the actual prototypes for the Vercel and Netlify adapters, the current implementation of adapter plugins by their current design also introduce an entry point, which also seems by nature of the design, e.g.

functions/
  my-function/
    my-function.js // userland entrypoint
    index.js // adapter wrapper that calls my-function.js
    package.json

Also see examples of this in the adapter plugins that have to copy a bunch of files around when preparing for uploading to the respective hosting platform


_Note: Assuming we get through #1008 without any issues like if things break without only a single file, otherwise as this is more of an enhancement / optimization, this could either be a 1.0 or post 1.0 feature. Tracking in the 1.0 Milestone for now ._

thescientist13 commented 1 year ago

So it seems like Rollup doesn't support this and seems like it's not a particularly easy thing to do.

However an interim solution seems to be something like this where we have to manually "squash" down into single file entry points by individually running each entry point through it's own Rollup config, instead of passing all entry points to Rollup into a single config, like we do now.