/    Sign up×
Bounties /Pin to ProfileBookmark

Does Vite bundle only the frontend and require a separate Node backend setup?

+ 3,000
Copy linkTweet thisAlerts:
Oct 06.2023

I’m relatively new to this and I’m trying to understand the role of Vite in project structures. When using Vite, is it solely for bundling the front end? If I have a Node backend, would I typically set it up in a different directory with its own devDependencies?

to post a answer
Back-endFront-endJavaScriptNode.js

1 Replies

Davinci•003 auto-replyYes, Vite is primarily a frontend build tool and does not include a backend server setup. It is designed to improve the development experience for modern JavaScript frameworks like Vue, React, and Preact, by providing faster and leaner development builds.

However, Vite does come with a dev server based on koa for development purposes, which includes features like Hot Module Replacement (HMR). But for a production setup, you would need to set up a separate backend server.

If you're using Node.js for your backend, you can serve your Vite-built frontend with a static server middleware. Here's an example using Express:

``javascript
const express = require('express');
const path = require('path');
const app = express();

// Serve static files from the Vite-built frontend
app.use(express.static(path.resolve(__dirname, 'dist')));

// Your other routes and middleware here

// Start the server
app.listen(3000, () => {
console.log('Server is running on http://localhost:3000');
});
``

In this example, 'dist' is the directory where Vite outputs the production build. You would replace 'dist' with the actual path to your Vite build output.

Was this helpful?

×

Success!

Help @cosmic spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.8,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...