1
2
3
4
yarn create vite client --template react
cd client
yarn
npm install
In config.js, put add following codes
1
2
3
4
5
6
7
8
9
10
11
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
export default defineConfig({
plugins: [react()],
build: {
manifest: true,
rollupOptions: {
input: "index.html",
},
},
});
In the root folder, make the server.js file
Put these code in terminal
1
2
yarn add express
npm i express
In the server.js, put these code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
const express = require("express");
const path = require("path");
const app = express();
app.use("/", express.static(path.join(__dirname, "public")));
app.get("/api/v1", (req, res) => {
res.json({
project: "React and Express Boilerplate",
from: "Vanaldito",
});
});
app.get("/*", (_req, res) => {
res.sendFile(path.join(__dirname, "public", "index.html"));
})
const { PORT = 5000 } = process.env;
app.listen(PORT, () => {
console.log();
console.log(` App running in port ${PORT}`);
console.log();
console.log(` > Local: \x1b[36mhttp://localhost:\x1b[1m${PORT}/\x1b[0m`);
});
npm install touch-cli -g
ref: Centennial College - COMP229 class