vitejs / vite

Next generation frontend tooling. It's fast!
http://vite.dev
MIT License
68.14k stars 6.15k forks source link

Surface SSR flag in vite.config.js #1644

Closed benmccann closed 3 years ago

benmccann commented 3 years ago

Is your feature request related to a problem? Please describe.

I would like some kind of flag passed to the vite.config.js that indicates if we're building for SSR as it's necessary to pass to the svelte compiler:

https://github.com/benmccann/vite-svelte/blob/a9346d957ca2630c0a9c8d4cdf17d7b9dc189c07/vite.config.js#L14

Describe the solution you'd like

Perhaps make something available in process.env.SSR or process.env.VITE_SSR

Describe alternatives you've considered

I found the whole command run on the command line with --ssr flag available in npm_lifecycle_script and npm_package_scripts_build_server environment variables, but it seems like those variables are not really meant for this and so it feels a little hacky: https://github.com/benmccann/vite-svelte/blob/a9346d957ca2630c0a9c8d4cdf17d7b9dc189c07/vite.config.js#L6

Additional context

I'm trying to bring support for Svelte to Vite. It looks rather nicely implemented!

yyx990803 commented 3 years ago

The "ssr or not" is part of the config, not the other way around.

A plugin should:

Essentially this means a plugin should not expect to hard code SSR target on initialization because it may need to perform both client and ssr transforms during dev.

benmccann commented 3 years ago

Thanks. I was just closing this with the same note as I'd just realized my mistake. I'm too used to Svelte's mental model :smile:

yyx990803 commented 3 years ago

Note rollup-plugin-svelte probably won't work out of the box particularly for its CSS handling. Combined with SSR a vite-specific fork may be needed.