Skip to content

Commit b87835d

Browse files
init
0 parents  commit b87835d

File tree

10 files changed

+191
-0
lines changed

10 files changed

+191
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/vendor
2+
composer.lock

composer.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"name": "laravel-frontend-presets/inertiajs",
3+
"description": "A Laravel frontend preset to get you up and running with Inertia.js",
4+
"keywords": ["laravel", "preset", "inertiajs"],
5+
"type": "library",
6+
"license": "MIT",
7+
"authors": [
8+
{
9+
"name": "Michael Dyrynda",
10+
"email": "[email protected]"
11+
}
12+
],
13+
"require": {
14+
"laravel/framework": "^5.5"
15+
},
16+
"autoload": {
17+
"psr-4": {
18+
"LaravelFrontendPresets\\InertiaJsPreset\\": "src/"
19+
}
20+
},
21+
"extra": {
22+
"laravel": {
23+
"providers": [
24+
"LaravelFrontendPresets\\InertiaJsPreset\\InertiaJsPresetServiceProvider"
25+
]
26+
}
27+
},
28+
"require-dev": {
29+
"orchestra/testbench": "^3.8"
30+
}
31+
}

src/InertiaJsPreset.php

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
3+
namespace LaravelFrontendPresets\InertiaJsPreset;
4+
5+
use Illuminate\Filesystem\Filesystem;
6+
use Illuminate\Foundation\Console\Presets\Preset;
7+
use Illuminate\Support\Arr;
8+
9+
class InertiaJsPreset extends Preset
10+
{
11+
public static function install()
12+
{
13+
static::updatePackages();
14+
static::updateBootstrapping();
15+
static::updateWelcomePage();
16+
static::scaffoldComponents();
17+
static::removeNodeModules();
18+
}
19+
20+
protected static function updatePackageArray(array $packages)
21+
{
22+
return array_merge([
23+
'inertiajs/inertia' => 'latest',
24+
'inertiajs/inertia-vue' => 'latest',
25+
], Arr::except($packages, [
26+
'jquery',
27+
]));
28+
}
29+
30+
protected static function updateBootstrapping()
31+
{
32+
copy(__DIR__.'/inertiajs-stubs/.babelrc', base_path('.babelrc'));
33+
34+
copy(__DIR__.'/inertiajs-stubs/webpack.mix.js', base_path('webpack.mix.js'));
35+
36+
copy(__DIR__.'/inertiajs-stubs/resources/js/app.js', resource_path('js/app.js'));
37+
}
38+
39+
protected static function updateWelcomePage()
40+
{
41+
(new Filesystem)->delete(resource_path('views/welcome.blade.php'));
42+
43+
copy(__DIR__.'/inertiajs-stubs/resources/views/app.blade.php', resource_path('views/app.blade.php'));
44+
}
45+
46+
protected static function scaffoldComponents()
47+
{
48+
(new Filesystem)->copyDirectory(__DIR__.'/inertiajs-stubs/resources/js/Shared', resource_path('js'));
49+
50+
(new Filesystem)->copyDirectory(__DIR__.'/inertiajs-stubs/resources/js/Pages', resource_path('js'));
51+
}
52+
53+
protected static function compileControllerStub()
54+
{
55+
//
56+
}
57+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace LaravelFrontendPresets\InertiaJsPreset;
4+
5+
use Illuminate\Support\ServiceProvider;
6+
use Illuminate\Foundation\Console\PresetCommand;
7+
8+
class IntertiaJsPresetServiceProvider extends ServiceProvider
9+
{
10+
public function boot()
11+
{
12+
PresetCommand::macro('inertiajs', function ($command) {
13+
IntertiaJsPreset::install();
14+
15+
$command->info('Inertia.js scaffolding installed successfully.');
16+
$command->info('Please run "npm install && npm run dev" to compile your fresh scaffolding.');
17+
});
18+
}
19+
}

src/inertiajs-stubs/.babelrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"plugins": ["@babel/plugin-syntax-dynamic-import"]
3+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<template>
2+
<layout>
3+
<h1>Welcome</h1>
4+
<p>Welcome to my first Inertia.js app!</p>
5+
</layout>
6+
</template>
7+
8+
<script>
9+
import Layout from '@/Shared/Layout'
10+
11+
export default {
12+
components: {
13+
Layout,
14+
},
15+
}
16+
</script>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<template>
2+
<main>
3+
<header>
4+
<inertia-link href="/">Home</inertia-link>
5+
<inertia-link href="/about">About</inertia-link>
6+
<inertia-link href="/contact">Contact</inertia-link>
7+
</header>
8+
<article>
9+
<slot />
10+
</article>
11+
</main>
12+
</template>
13+
14+
<script>
15+
import { InertiaLink } from 'inertia-vue'
16+
17+
export default {
18+
components: {
19+
InertiaLink,
20+
},
21+
}
22+
</script>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import Inertia from 'inertia-vue'
2+
import Vue from 'vue'
3+
4+
let app = document.getElementById('app')
5+
6+
new Vue({
7+
render: h => h(Inertia, {
8+
props: {
9+
initialPage: JSON.parse(app.dataset.page),
10+
resolveComponent: (component) => {
11+
return import(`@/Pages/${component}`).then(module => module.default)
12+
},
13+
},
14+
}),
15+
}).$mount(app)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
6+
<link href="{{ mix('/css/app.css') }}" rel="stylesheet">
7+
<script src="{{ mix('/js/app.js') }}" defer></script>
8+
</head>
9+
<body>
10+
11+
@inertia
12+
13+
</body>
14+
</html>

src/inertiajs-stubs/webpack.mix.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const mix = require('laravel-mix')
2+
const path = require('path')
3+
4+
mix.js('resources/js/app.js', 'public/js').webpackConfig({
5+
output: { chunkFilename: 'js/[name].[contenthash].js' },
6+
resolve: {
7+
alias: {
8+
'vue$': 'vue/dist/vue.runtime.js',
9+
'@': path.resolve('resources/js'),
10+
},
11+
},
12+
})

0 commit comments

Comments
 (0)