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

refactor: use afterResolving instead of Blade facade #97

Merged
merged 3 commits into from
Aug 27, 2021
Merged
Changes from all commits
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
28 changes: 15 additions & 13 deletions src/ViteServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Innocenzi\Vite;

use Illuminate\Support\Facades\Blade;
use Illuminate\View\Compilers\BladeCompiler;
use Innocenzi\Vite\Commands\ExportConfigurationCommand;
use Innocenzi\Vite\Commands\GenerateAliasesCommand;
use Spatie\LaravelPackageTools\Package;
Expand All @@ -19,24 +19,26 @@ public function configurePackage(Package $package): void
->hasCommand(GenerateAliasesCommand::class);
}

public function registeringPackage()
public function bootingPackage()
{
$this->app->singleton(Vite::class, fn () => new Vite());

Blade::directive('vite', function ($entryName = null) {
if (! $entryName) {
return '<?php echo vite_tags() ?>';
}
$this->app->afterResolving('blade.compiler', function (BladeCompiler $compiler) {
$compiler->directive('vite', function ($entryName = null) {
if (! $entryName) {
return '<?php echo vite_tags() ?>';
}

return sprintf('<?php echo vite_entry(e(%s)); ?>', $entryName);
});
return sprintf('<?php echo vite_entry(e(%s)); ?>', $entryName);
});

Blade::directive('client', function () {
return '<?php echo vite_client(); ?>';
});
$compiler->directive('client', function () {
return '<?php echo vite_client(); ?>';
});

Blade::directive('react', function () {
return '<?php echo vite_react_refresh_runtime(); ?>';
$compiler->directive('react', function () {
return '<?php echo vite_react_refresh_runtime(); ?>';
});
});
}
}