React SSR template does not respect configuration file
aleyrizvi opened this issue · 6 comments
Hello,
server.js
line 7:
const port = process.env.PORT || 5173
This does not read configuration from vite.config.ts.
The port defaults to 5173
even if we specify it in config file:
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react-swc'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
server: {
port: 3000,
strictPort: true
}
})
This is intentional. The server.js
file is meant to be used in both dev and prod, and when deployed your dev deps (including any Vite plugins) used in your Vite config won't exist, so we can't read the Vite config in prod.
The only other way I guess is to bundle the server.js
script, but we chosed the current setup to not bundle it. Or we could respect the port only in dev, but I think it's also worth keeping the code simple for now.
This is intentional. The
server.js
file is meant to be used in both dev and prod, and when deployed your dev deps (including any Vite plugins) used in your Vite config won't exist, so we can't read the Vite config in prod.The only other way I guess is to bundle the
server.js
script, but we chosed the current setup to not bundle it. Or we could respect the port only in dev, but I think it's also worth keeping the code simple for now.
Thank you for the response.
What about something like: vite_port || process.env.PORT || 5173
?
How would we able to get vite_port
?
How would we able to get
vite_port
?
vite.config.server.port
I can update all the templates if you like and create a pull request.
Closing with #49 (comment)