-
-
Save abirrugal/3b3393b38dd7c949136f93c4715f458e to your computer and use it in GitHub Desktop.
Everything that you need to create a new Laravel application with React.js, Inertia.js and Vite.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}"> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<title>Laravel</title> | |
@viteReactRefresh | |
@vite(['resources/css/app.css', 'resources/js/app.jsx']) | |
@inertiaHead | |
</head> | |
<body> | |
@inertia | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react' | |
import {createRoot} from 'react-dom/client' //here | |
import {createInertiaApp } from '@inertiajs/inertia-react' | |
import {resolvePageComponent} from 'laravel-vite-plugin/inertia-helpers' | |
createInertiaApp({ | |
resolve: (name) => resolvePageComponent(`./Pages/${name}.jsx`,import.meta.glob('./Pages/**/*.jsx')), | |
setup({ el, App, props }) { | |
createRoot(el).render(<App {...props} />) //and here | |
}, | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"private": true, | |
"scripts": { | |
"dev": "vite", | |
"build": "vite build" | |
}, | |
"devDependencies": { | |
"axios": "^1.1.2", | |
"laravel-vite-plugin": "^0.7.2", | |
"lodash": "^4.17.19", | |
"postcss": "^8.1.14", | |
"vite": "^4.0.0" | |
}, | |
"dependencies": { | |
"@inertiajs/inertia-react": "^0.8.1", | |
"@inertiajs/react": "^1.0.0", | |
"@vitejs/plugin-react": "^3.1.0", | |
"react": "^18.2.0", | |
"react-dom": "^18.2.0" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useState } from 'react'; | |
const Test = () => { | |
return ( | |
<h1>This is test component</h1> | |
) | |
} | |
export default Test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { defineConfig } from 'vite'; | |
import laravel from 'laravel-vite-plugin'; | |
import react from '@vitejs/plugin-react'; | |
export default defineConfig({ | |
plugins: [ | |
react(), | |
laravel({ | |
input: ['resources/css/app.css', 'resources/js/app.js'], | |
refresh: true, | |
}), | |
], | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Illuminate\Support\Facades\Route; | |
use Inertia\Inertia; | |
/* | |
|-------------------------------------------------------------------------- | |
| Web Routes | |
|-------------------------------------------------------------------------- | |
| | |
| Here is where you can register web routes for your application. These | |
| routes are loaded by the RouteServiceProvider within a group which | |
| contains the "web" middleware group. Now create something great! | |
| | |
*/ | |
Route::get('/', function () { | |
return Inertia::render('Test'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment