feat: use vite

This commit is contained in:
ckt1031 2023-07-08 14:58:42 +08:00
parent 2756554f7c
commit 37d7afcedc
3 changed files with 56 additions and 9 deletions

View File

@ -14,5 +14,6 @@
<body> <body>
<noscript>You need to enable JavaScript to run this app.</noscript> <noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div> <div id="root"></div>
<script type="module" src="./src/index.js"></script>
</body> </body>
</html> </html>

View File

@ -3,22 +3,22 @@
"version": "0.1.0", "version": "0.1.0",
"private": true, "private": true,
"dependencies": { "dependencies": {
"axios": "^0.27.2", "axios": "^1.4.0",
"history": "^5.3.0", "history": "^5.3.0",
"marked": "^4.1.1", "marked": "^5.1.1",
"react": "^18.2.0", "react": "^18.2.0",
"react-dom": "^18.2.0", "react-dom": "^18.2.0",
"react-dropzone": "^14.2.3", "react-dropzone": "^14.2.3",
"react-router-dom": "^6.3.0", "react-router-dom": "^6.14.1",
"react-scripts": "5.0.1", "react-scripts": "5.0.1",
"react-toastify": "^9.0.8", "react-toastify": "^9.1.3",
"react-turnstile": "^1.0.5", "react-turnstile": "^1.1.1",
"semantic-ui-css": "^2.5.0", "semantic-ui-css": "^2.5.0",
"semantic-ui-react": "^2.1.3" "semantic-ui-react": "^2.1.4"
}, },
"scripts": { "scripts": {
"start": "react-scripts start", "start": "vite preview",
"build": "react-scripts build", "build": "vite build",
"test": "react-scripts test", "test": "react-scripts test",
"eject": "react-scripts eject" "eject": "react-scripts eject"
}, },
@ -41,7 +41,9 @@
] ]
}, },
"devDependencies": { "devDependencies": {
"prettier": "^2.7.1" "@vitejs/plugin-react": "^4.0.2",
"prettier": "^2.7.1",
"vite": "^4.4.2"
}, },
"prettier": { "prettier": {
"singleQuote": true, "singleQuote": true,

44
web/vite.config.js Normal file
View File

@ -0,0 +1,44 @@
import fs from "node:fs";
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import * as esbuild from "esbuild";
const sourceJSPattern = /\/src\/.*\.js$/;
const rollupPlugin = (matchers) => ({
name: "js-in-jsx",
load(id) {
if (matchers.some(matcher => matcher.test(id))) {
const file = fs.readFileSync(id, { encoding: "utf-8" });
return esbuild.transformSync(file, { loader: "jsx" });
}
}
});
export default defineConfig({
plugins: [
react()
],
build: {
outDir: "./build",
rollupOptions: {
plugins: [
rollupPlugin([sourceJSPattern])
],
},
commonjsOptions: {
transformMixedEsModules: true,
},
},
optimizeDeps: {
esbuildOptions: {
loader: {
".js": "jsx",
},
},
},
esbuild: {
loader: "jsx",
include: [sourceJSPattern],
exclude: [],
},
});