antlur / laravel-static-export
Export your laravel site as static files
Fund package maintenance!
Antlur
Requires
- php: ^8.1
- laravel/framework: ^10.0
- spatie/laravel-package-tools: ^1.14.0
Requires (Dev)
- larastan/larastan: ^2.0.1
- laravel/pint: ^1.0
- nunomaduro/collision: ^7.8
- orchestra/testbench: ^8.8
- pestphp/pest: ^2.20
- pestphp/pest-plugin-arch: ^2.5
- pestphp/pest-plugin-laravel: ^2.0
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
README
Host your Laravel site on Netlify, Vercel, or any other static site host. This package will generate static files from your Laravel site with very little setup. A convenient attribute is provided to provide routes with dynamic parameters.
Installation
You can install the package via composer:
composer require antlur/laravel-static-export
You can publish the config file with:
php artisan vendor:publish --tag="static-export-config"
This is the contents of the published config file:
return [ 'output_path' => base_path('dist'), 'clear_before_export' => true, ];
Usage
php artisan export
Dynamic Data during static site generation
When generating the static site, you can use the ExportPaths attribute to define which routes should be generated. This is useful when you have dynamic data that you want to generate static pages for. For example, if you have a blog and you want to generate static pages for each blog post, you can use the ExportPaths attribute to define which routes should be generated. The rest of your logic can be handled as if it was a normal Laravel application.
// web.php Route::get('/blog/{slug}', [BlogController::class, 'show']); // app/Http/Controllers/BlogController.php use Antlur\Export\Attributes\ExportPaths; class BlogController { // You can pass a class that implements PathProvider #[ExportPaths(BlogPostPaths::class)] public function show(string $name) {} // Or you can pass an array of paths directly #[ExportPaths(['/blog/first-post', '/blog/second-post'])] public function show(string $name) {} } // app/PathProviders/BlogPostPaths.php class BlogPostPaths implements \Antlur\Export\Contracts\PathProvider { public function paths(): array { return [ '/blog/first-post', '/blog/second-post', ]; } }
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.