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

Process Serverless Output with Vite #1

Open
zachleat opened this issue Mar 17, 2022 · 6 comments
Open

Process Serverless Output with Vite #1

zachleat opened this issue Mar 17, 2022 · 6 comments
Labels
enhancement New feature or request

Comments

@zachleat
Copy link
Member

zachleat commented Mar 17, 2022

I previously thought this wasn’t going to work because Vite was too big but I think for some projects it might work?

image

Would need a combination of using rollup plugin-virtual to pass strings into rollup config
rollup/rollup#3276 (comment)
https://github.com/rollup/plugins/tree/master/packages/virtual

And vite’s build.write false option to get the rollup output back as an object
https://vitejs.dev/config/#build-write

@zachleat zachleat added the enhancement New feature or request label Mar 17, 2022
@AleksandrHovhannisyan
Copy link

AleksandrHovhannisyan commented Mar 22, 2022

This would be wonderful! I think it may also pave the way for Slinkity to be able to support Serverless, but maybe that's a separate issue (@Holben888 sorry to summon you—what do you think?).

(Use case: I want to be able to support URL sharing and server-render React components based on query params: AleksandrHovhannisyan/fluid-type-scale-calculator#17)

@bholmesdev
Copy link

bholmesdev commented Mar 22, 2022

Oh ho ho, did somebody say build.write: false? That's how we server render components in Slinkity today! I think expanding this usage to HTML parsing could aid in serverless as well. Here's our Vite build setup for reference.

We also wrote a thin abstraction called toCommonJSModule to return modules in-memory depending on the environment. This uses vite.server.ssrLoadModule when in development, and vite.build with write: false for production. It also uses a build helper we wrote to efficiently batch multiple build requests for the same module. Not sure if all of this will be of use, but I wanted to call them out for reference 😁

@bholmesdev
Copy link

bholmesdev commented Mar 22, 2022

Also, an important caveat I want to mention: Vite production builds aren't the fastest around. Since they target HTML files as the entrypoint and could compile SCSS files on-the-fly as well, it's easy to creep into 1 second or more for a single page. I'm curious if certain files like SCSS should be processed ahead-of-time / before serverless requests, with the caveat that you can't use template strings to dynamically import scss.

<!--allowed and bundled at build time, before serverless requests-->
<link rel="stylesheet" href="/styles/staticPath.scss">

<!--not allowed!-->
<link rel="stylesheet" href="/styles/{{ params.dynamicPath }}.scss">

@bholmesdev
Copy link

Also want to call out that Astro has 100% ruled out Vite in a serverless environment. Any bundling or analysis of non-JS assets occurs at build time, while frontmatter (essentially 11ty's data cascade) is free to process on serverless.

@AleksandrHovhannisyan
Copy link

Also want to call out that Astro has 100% ruled out Vite in a serverless environment.

@bholmesdev Does this mean that the use case I described is not possible?

@bholmesdev
Copy link

@AleksandrHovhannisyan So it's not impossible, just not recommended as the only option. the length of Vite builds and the size of the bundle make it a no-go for certain use cases. We definitely need a Vite-less option for serverless alongside the Vite-ful solution at least.

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

No branches or pull requests

3 participants