You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The user cannot use Vite constants such as import.meta.env.
The user cannot use TypeScript (without using an extra tool such as ts-node).
If the user makes a change to server.js then the user has to manually stop and re-start the server.
Suggested solution
We add an argument to the CLI command vite.
$ vite ./server.js
The argument is optional and if omitted Vite behaves as it does today (it starts Vite's built-in dev server).
// server.jsimportexpressfrom'express'importvitefrom'vite'startServer()asyncfunctionstartServer(){constapp=express()const{middlewares: viteMiddleware}=awaitvite.createServer({server: {middlewareMode: 'ssr'},})app.use(viteMiddleware)app.listen(process.env.PORT||3000)console.log(`Server running at http://localhost:${port}`)}
The whole vite.loadSSRModule dance would be taken care of.
We can even consider adding support for HMR and, if HMR is not applicable, to automatically reload the server by killing process.env.PORT with e.g. kill-port. (It's a common convention to use process.env.PORT as server port.)
The user can also define the server entry with vite.config.js#server.
brillout
changed the title
Support server entry — vite path/to/server.js / vite.config.js#server.
Support server entry — $ vite path/to/server.js / vite.config.js#server.
Jan 5, 2022
This would be awesome! I was just about to post about wanting to create a plugin that creates a server in middleware mode (ssr) and either works with Vite or allows you to replace the server with your own. This issue seems to fit that bill. In my scenario, I don't want the user to have to define a server.js though. I want it to be provided by my custom plugin out of the box.
Sort of on the same topic, but could it be possible to allow for a custom index.html (like ssr mode allows) but allow it to be passed to the vite dev server (instead of it assuming there's a local file at the root)? The only real reason I use ssr mode is because, similar to abstracting away server.js from users, I want to do the same for the index.html and entry.js. I've already accomplished this via my own custom package that people need to use. Would love to be able to do these things via a plugin or natively with Vite.
Clear and concise description of the problem
Vite does not support server entries.
For example, the
playground/ssr-vue/server.js
file is not processed by Vite which means:import.meta.env
.ts-node
).server.js
then the user has to manually stop and re-start the server.Suggested solution
We add an argument to the CLI command
vite
.The argument is optional and if omitted Vite behaves as it does today (it starts Vite's built-in dev server).
The whole
vite.loadSSRModule
dance would be taken care of.We can even consider adding support for HMR and, if HMR is not applicable, to automatically reload the server by killing
process.env.PORT
with e.g. kill-port. (It's a common convention to useprocess.env.PORT
as server port.)The user can also define the server entry with
vite.config.js#server
.# No need to specify the server entry here $ vite
Alternative
No response
Additional context
This ticket is part of Vite Server RFC.
Validations
The text was updated successfully, but these errors were encountered: