Open MiguelDeRoudriges opened 1 year ago
I encountered the same problem as you with vite-ssr build
generating a development version of the client. This is using vite 4 and vue 3.
After some hacky debugging I could generate the correct production build by adding an additional argument for defaultNodeEnv
of resolveConfig
.
I.e. Change this:
to this:
export async function resolveViteConfig(mode?: string) {
return resolveConfig(
{},
'build',
mode || process.env.MODE || process.env.NODE_ENV,
mode || process.env.MODE || process.env.NODE_ENV
)
}
Then running NODE_ENV=production npm run build
in my project (which calls vite-ssr build
) I'd get the output I was expecting and not a development build with warnings etc.
I also noticed that the mode isn't being sent through to the resolveViteConfig
function so not sure why that is even an argument to the function:
https://github.com/frandiox/vite-ssr/blob/50461a4e0ebf431fdd96771e069a5e759e275b6b/src/build/index.ts#L24
https://github.com/frandiox/vite-ssr/blob/50461a4e0ebf431fdd96771e069a5e759e275b6b/src/config.ts#L70
I'm not sure the impacts this hack might have so best if someone with knowledge on this project and vite have a look. For now I've gotten around it in my build process (docker) by adding:
RUN sed -i "s/ return (0, vite_1.resolveConfig)({}, 'build', mode || process.env.MODE || process.env.NODE_ENV);/ return (0, vite_1.resolveConfig)({}, 'build', mode || process.env.MODE || process.env.NODE_ENV, mode || process.env.MODE || process.env.NODE_ENV);/" ./node_modules/vite-ssr/config.js
...before I call the build command :D Very hacky I know and will break after an update! I'm not using it on a professional site, so not too bothered for now. Hopefully this will help get it fixed properly in the mean time.
Here is my package json:
When i do
npm run build
and then run my express server. My application runs in development mode.When i try to log "import.meta.env" it shows me that
mode
at the same time is"production"
andPROD
is false. How is this even possible?