Make a monorepo with express
This commit is contained in:
parent
04ac2eeb0d
commit
f33dd20569
7 changed files with 46 additions and 4 deletions
|
@ -12,7 +12,7 @@
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { createRoot } from "react-dom/client";
|
import { createRoot } from "react-dom/client";
|
||||||
|
|
||||||
import App from "./src/app.jsx";
|
import App from "./src/client/app.jsx";
|
||||||
|
|
||||||
createRoot(document.getElementById("root")).render(
|
createRoot(document.getElementById("root")).render(
|
||||||
React.createElement(
|
React.createElement(
|
||||||
|
|
10
package.json
10
package.json
|
@ -1,11 +1,21 @@
|
||||||
{
|
{
|
||||||
"type": "module",
|
"type": "module",
|
||||||
|
"scripts": {
|
||||||
|
"dev": "concurrently 'npm run dev:client' 'npm run dev:server'",
|
||||||
|
"dev:client": "vite --open",
|
||||||
|
"dev:server": "nodemon src/server/server.js",
|
||||||
|
"build": "vite build",
|
||||||
|
"start": "node src/server/server.js"
|
||||||
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"express": "^4.19.2",
|
||||||
"react": "^18.3.1",
|
"react": "^18.3.1",
|
||||||
"react-dom": "^18.3.1"
|
"react-dom": "^18.3.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"autoprefixer": "^10.4.19",
|
"autoprefixer": "^10.4.19",
|
||||||
|
"concurrently": "^8.2.2",
|
||||||
|
"nodemon": "^3.1.0",
|
||||||
"postcss": "^8.4.38",
|
"postcss": "^8.4.38",
|
||||||
"prettier": "^3.3.2",
|
"prettier": "^3.3.2",
|
||||||
"prettier-plugin-css-order": "^2.1.2",
|
"prettier-plugin-css-order": "^2.1.2",
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
export default () => (
|
|
||||||
<h1 className="text-4xl font-extrabold">Using React and Tailwind</h1>
|
|
||||||
);
|
|
17
src/client/app.jsx
Normal file
17
src/client/app.jsx
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
export default () => {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<h1 className="text-4xl font-extrabold">React + Express + Tailwind</h1>
|
||||||
|
<button
|
||||||
|
className="rounded bg-blue-500 px-4 py-2 font-bold text-white hover:bg-blue-700"
|
||||||
|
onClick={() => {
|
||||||
|
fetch("/api")
|
||||||
|
.then((response) => response.text())
|
||||||
|
.then((data) => alert(data));
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Click me!
|
||||||
|
</button>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
10
src/server/app.js
Normal file
10
src/server/app.js
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
import express from "express";
|
||||||
|
const app = express();
|
||||||
|
|
||||||
|
const rootRouter = express.Router();
|
||||||
|
rootRouter.get("/", (_, res) => res.send("Backend is working!"));
|
||||||
|
|
||||||
|
app.use(express.static("dist"));
|
||||||
|
app.use("/api", rootRouter);
|
||||||
|
|
||||||
|
export default app;
|
3
src/server/server.js
Normal file
3
src/server/server.js
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
import app from "./app.js";
|
||||||
|
|
||||||
|
app.listen(3000);
|
|
@ -1,6 +1,11 @@
|
||||||
import { defineConfig } from "vite";
|
import { defineConfig } from "vite";
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
|
server: {
|
||||||
|
proxy: {
|
||||||
|
"/api": "http://localhost:3000",
|
||||||
|
},
|
||||||
|
},
|
||||||
esbuild: {
|
esbuild: {
|
||||||
jsxInject: `import React from 'react'`,
|
jsxInject: `import React from 'react'`,
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue