我决定配置由 create-react-app 创建的 React 应用程序以开始使用 vite。在遵循一些文档之后,我配置了所需的文件。当我vite在应用程序的根目录中运行时,它会运行,但不幸的是,由于 404 错误,我无法访问这些文件。奇怪的是,对于我的同事来说,它运行。当我更改为react-scripts它时,它运行成功。以下是我的应用程序的一些配置:
vite.config.ts
import { defineConfig } from \'vite\'\nimport react from \'@vitejs/plugin-react\'\nimport path from \'path\'\n\nexport default defineConfig({\n plugins: [react()],\n build: {\n outDir: \'build\',\n },\n resolve: {\n alias: {\n \'@\': path.resolve(__dirname, \'src\'),\n },\n },\n})\nRun Code Online (Sandbox Code Playgroud)\ntsconfig.json
{\n "compilerOptions": {\n "target": "ESNext",\n "types": ["vite/client"],\n "lib": ["dom", "dom.iterable", "esnext"],\n "allowJs": true,\n "skipLibCheck": true,\n "esModuleInterop": true,\n "allowSyntheticDefaultImports": true,\n "strict": true,\n "forceConsistentCasingInFileNames": true,\n "noFallthroughCasesInSwitch": true,\n "module": "esnext",\n "moduleResolution": "node",\n "resolveJsonModule": true,\n "isolatedModules": …Run Code Online (Sandbox Code Playgroud)