Closed benmccann closed 3 years ago
The "ssr or not" is part of the config, not the other way around.
build.ssr
option.A plugin should:
ssr
flag passed to resolveId
, load
and transform
configResolved
to check if the build is targeting SSR (by storing config.build.ssr
in a variable)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.
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:
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.
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
orprocess.env.VITE_SSR
Describe alternatives you've considered
I found the whole command run on the command line with
--ssr
flag available innpm_lifecycle_script
andnpm_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#L6Additional context
I'm trying to bring support for Svelte to Vite. It looks rather nicely implemented!