Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[2.x] Add Inertia SSR Support #1012

Merged
merged 7 commits into from
Mar 25, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add --ssr option.
  • Loading branch information
xiCO2k committed Mar 20, 2022
commit 77cca0ca6a3326f92967913b6da3ae8d6595cec4
44 changes: 33 additions & 11 deletions src/Console/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class InstallCommand extends Command
protected $signature = 'jetstream:install {stack : The development stack that should be installed}
{--teams : Indicates if team support should be installed}
{--pest : Indicates if Pest should be installed}
{--ssr : Indicates if Inertia SSR support should be installed}
{--composer=global : Absolute path to the Composer binary which should be used to install packages}';

/**
Expand Down Expand Up @@ -345,16 +346,6 @@ protected function installInertiaStack()
$this->output->write($output);
});

// SSR...
(new Process([$this->phpBinary(), 'artisan', 'vendor:publish', '--provider=Inertia\ServiceProvider', '--force'], base_path()))
->setTimeout(null)
->run(function ($type, $output) {
$this->output->write($output);
});

$this->replaceInFile("'enabled' => false", "'enabled' => true", config_path('inertia.php'));
$this->replaceInFile("mix --production", "mix --production --mix-config=webpack.ssr.mix.js && mix --production", base_path('package.json'));

$this->installMiddlewareAfter('SubstituteBindings::class', '\App\Http\Middleware\HandleInertiaRequests::class');

// Models...
Expand Down Expand Up @@ -396,7 +387,6 @@ protected function installInertiaStack()
copy(__DIR__.'/../../stubs/public/css/app.css', public_path('css/app.css'));
copy(__DIR__.'/../../stubs/resources/css/app.css', resource_path('css/app.css'));
copy(__DIR__.'/../../stubs/inertia/resources/js/app.js', resource_path('js/app.js'));
copy(__DIR__.'/../../stubs/inertia/resources/js/ssr.js', resource_path('js/ssr.js'));

// Flush node_modules...
// static::flushNodeModules();
Expand All @@ -418,6 +408,10 @@ protected function installInertiaStack()
$this->installInertiaTeamStack();
}

if ($this->option('ssr')) {
$this->installInertiaSsrStack();
}

$this->line('');
$this->info('Inertia scaffolding installed successfully.');
$this->comment('Please execute "npm install && npm run dev" to build your assets.');
Expand Down Expand Up @@ -497,6 +491,34 @@ protected function ensureApplicationIsTeamCompatible()
copy(__DIR__.'/../../database/factories/TeamFactory.php', base_path('database/factories/TeamFactory.php'));
}

/**
* Install the Inertia SSR stack into the application.
*
* @return void
*/
protected function installInertiaSsrStack()
{
$this->updateNodePackages(function ($packages) {
return [
'@inertiajs/server' => '^0.1.0',
'@vue/server-renderer' => '^3.2.31',
'webpack-node-externals' => '^3.0.0'
] + $packages;
});

copy(__DIR__.'/../../stubs/inertia/webpack.ssr.mix.js', base_path('webpack.ssr.mix.js'));
copy(__DIR__.'/../../stubs/inertia/resources/js/ssr.js', resource_path('js/ssr.js'));

(new Process([$this->phpBinary(), 'artisan', 'vendor:publish', '--provider=Inertia\ServiceProvider', '--force'], base_path()))
->setTimeout(null)
->run(function ($type, $output) {
$this->output->write($output);
});

$this->replaceInFile("'enabled' => false", "'enabled' => true", config_path('inertia.php'));
$this->replaceInFile("mix --production", "mix --production --mix-config=webpack.ssr.mix.js && mix --production", base_path('package.json'));
}

/**
* Install the service provider in the application configuration file.
*
Expand Down