I enabled https in vite.config
because I need it for development. But I don’t know how to use this field in production since I’m going to use Nginx and let’s encrypt. Do I need to check if I’m in development mode with an environment variable?
I’m using vite with SvelteKit.
Here’s my vite.config
import { sveltekit } from '@sveltejs/kit/vite';
import { defineConfig, loadEnv } from 'vite';
import fs from 'fs';
export default defineConfig(({ command, mode }) => {
const env = loadEnv(mode, process.cwd(), '');
return {
plugins: [sveltekit()],
server: {
https: {
key: fs.readFileSync(env.HTTPS_KEY),
cert: fs.readFileSync(env.HTTPS_CERTS)
},
proxy: {}
}
};
});
2
Answers
If you are looking for production solution I’d suggest using a process manager like pm2
You can build a server using standard config and running
vite build
and configure pm2 with ecosystem file to use the compiled projectExample on how to use env vars for future reference:
Hope that helps!