vite-plugin-node icon indicating copy to clipboard operation
vite-plugin-node copied to clipboard

It disrupts the static serving of Vite

Open branaway opened this issue 2 years ago • 2 comments

Hi,

The Vite can serve static assets in the public dir by default. This feature would be disrupted with the presence of this plugin in the Vite.config.js. Any saves here?

branaway avatar Jan 14 '23 23:01 branaway

@branaway I know this might be a bit late for you, but hopefully still useful for you and others in new projects :-)

I found myself in the same boat in that I wanted to run Vite for my frontend as well as my backend. To allow them both to serve independently I decided to spin up 2 Vite servers, one for the UI and one for the API. I've put my template/boilerplate into a repo that will hopefully be a helpful reference.

The idea behind running them as separate servers is that it closely resembles the fact that they can be deployed independently. The UI can be built for production and deployed to any static asset hosting service and the API can be deployed to whatever your preferred hosting solution is, with suitable proxy/domain configuration.

jvdl avatar Jul 28 '24 10:07 jvdl

For anyone else stumbling across this issue as I was, I ended up just adding the routes I needed directly into the Vite config file: https://github.com/vitejs/vite/discussions/20025

This allowed me to run a local API on the same HTTP server as Vite was serving a React app, without disrupting the React app, and without having to worry about proxying API requests from a different local HTTP server.

adam-nielsen avatar May 13 '25 01:05 adam-nielsen