安裝React
code:bash
yarn create @vitejs/app
npm create vite@latest
cd react-app
npm install
npm run dev
code:bash
npx create-next-app@latest
cd react-app
npm run dev
esbuild、esbuild-server、tsx、react、react-dom、twind、wouter…
code:esbuild.ts
import { createServer } from "esbuild-server";
import esbuild from "esbuild";
const mode = process.argv2 === "--watch" ? "watch" : "build"; const esbuildOptions = {
bundle: true,
sourcemap: true,
loader: { ".svg": "text" },
outdir: "public",
logLevel: "info",
};
if (mode === "build") {
esbuild
.build({
...esbuildOptions,
})
.catch(() => process.exit(1));
}
if (mode === "watch") {
const port = parseInt(process.env.PORT || "8080");
console.log(Development server started at http://localhost:${port});
createServer(
{ ...esbuildOptions },
{ static: "public", historyApiFallback: true, port },
).start();
}
code:package.json
{
// ...
"scripts": {
"dev": "tsx esbuild.ts --watch",
"build": "tsx esbuild.ts"
}
// ...
}
code:public/index.html
<html>
<body>
<script type="module" src="./index.js"></script>
<div id="root"></div>
</body>
</html>
目前已不推薦使用
code:bash
npx create-react-app@5.0.0 react-app
cd react-app
npm start
npx preact-cli create default my-project