Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use vite-plugin-node along with @vitejs/plugin-react #35

Open
subodhpareek18 opened this issue Mar 16, 2022 · 6 comments
Open

Use vite-plugin-node along with @vitejs/plugin-react #35

subodhpareek18 opened this issue Mar 16, 2022 · 6 comments

Comments

@subodhpareek18
Copy link

subodhpareek18 commented Mar 16, 2022

Apologies if this is a noob level question. I'm new to both vite and vite-node. I want to build an app with both a backend and a front end. As I understand vite enables you to do the front end part easily but without the backend hmr which this plugin is built for.

However I haven't figured out how to combine both with independent server and client directories each hosting it's own set of files, with the server/index.ts having its own /api end points and falling back to client for the remaining * routes. I've gone through the examples here but couldn't find what I was looking for.

Any help would be appreciated, thanks!

@subodhpareek18 subodhpareek18 changed the title Use vite-node along with react plugin Use vite-plugin-node along with @vitejs/plugin-react Mar 16, 2022
@Falci
Copy link

Falci commented Mar 20, 2022

I have the problem.

index.html is not generated when using both plugins: [react(), ...VitePluginNode()]

@axe-me
Copy link
Owner

axe-me commented May 11, 2022

i think it's better to keep your frontend and backend separated. At your frontend vite config just proxy the /api to your backend URL. See: https://vitejs.dev/config/#server-proxy

@andersaamodt
Copy link

Is there a way to have both in one project with vite-plugin-node? Enabling vite-plugin-node config disables compiling the frontend for me.

@iandoesallthethings
Copy link

@andersaamodt I'm having a similar problem with svelte, so seconding this question. Aiming for something like this:

// express/app.ts
import express from 'express'
const app = express()

app.get('/legacy', (req, res) => {
	res.send('Hello World from express!')
})

export const expressApp = app

// vite.config.js
plugins: [
  sveltekit(),
  ...VitePluginNode({ 
    adapter: 'express', 
    appPath: './express/app.ts', 
    exportName: 'expressApp' 
  })
]

The express routes work fine, but it looks like the sveltekit routes are being overwritten even if I change the order of the plugins.

@cainrus
Copy link

cainrus commented Jan 3, 2024

FYI: #95 (comment)

@nbarpujari-bardavon
Copy link

I am using this package in a fullstack setup along with remix.
I had to patch the package to hmr: true (here). Without this patch HMR for react stops working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants