如果在 Laravel10 + Inertia + React + Sail 中,http://localhost/ 的页面完全空白,请执行以下步骤

 

在以下环境下,当访问http://localhost/时,屏幕显示完全为空白,所以我进行了调查以找出原因。

"@headlessui/react": "^1.4.2",
"@inertiajs/react": "^1.0.0",
"@tailwindcss/forms": "^0.5.3",
"@vitejs/plugin-react": "^4.0.3",
"autoprefixer": "^10.4.12",
"axios": "^1.1.2",
"laravel-vite-plugin": "^0.8.0",
"postcss": "^8.4.18",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"tailwindcss": "^3.2.1",
"vite": "^4.0.0"

 

只需要一个选项:

在控制台上

GET http://0.0.0.0:5173/resources/js/app.jsx net::ERR_ABORTED 404 (Not Found)
GET http://0.0.0.0:5173/resources/js/Pages/Welcome.jsx net::ERR_ABORTED 404 (Not Found)

尝试了一番后,发现需要在vite.config.js文件中添加以下内容。

 

export default defineConfig({
    plugins: [
        laravel({
            input: "resources/js/app.jsx",
            ssr: "resources/js/ssr.jsx",
            refresh: true,
        }),
        react(),
    ],
    // ここから
    server: {
        host: "0.0.0.0",
        hmr: {
            clientPort: 5173,
            host: "localhost",
        },
    },
    // ここまで
});
广告
将在 10 秒后关闭
bannerAds