spatie/laravel-export
Export your Laravel app as a static site bundle. Crawls your routes to generate HTML for discovered URLs and includes the public directory for assets. Ideal for blogs/sites built with Laravel, then deployed to Netlify or any static host.
public directory, ensuring assets (images, JS, CSS) are included in the export.paths or use middleware to block sensitive routes (e.g., app/Http/Middleware/BlockExportMiddleware).php artisan export and validate asset URLs.use_streaming: true to avoid memory issues.include_files.public directory.public or explicitly included via include_files.composer require spatie/laravel-export./blog/*) using php artisan export.include_files and exclude_file_patterns.php artisan vendor:publish --provider=Spatie\Export\ExportServiceProvider.config/export.php:
'paths' => ['/', '/blog', '/about'], // Explicit routes
'include_files' => ['public', 'storage/app/public'], // Additional assets
'use_streaming' => true, // For large sites
'before' => [
'build' => 'npm run build',
],
'after' => [
'deploy' => './vendor/bin/netlify deploy --prod',
],
git push to main:
# .github/workflows/export.yml
jobs:
export:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- run: composer install
- run: npm install
- run: npm run build
- run: php artisan export
- run: ./vendor/bin/netlify deploy --prod
X-Laravel-Export header to bypass auth during export:
// app/Http/Middleware/TrustProxies.php
public function handle($request, Closure $next) {
if ($request->header('X-Laravel-Export')) {
return $next($request->withoutHeaders('X-Laravel-Export'));
}
return $next($request);
}
@verbatim or static data).php artisan export.spatie/crawler and Laravel core dependencies regularly.config/export.php changes (e.g., new paths, hooks).export directory (e.g., .gitignore exceptions for critical sites).--skip-all to debug without hooks:
php artisan export --skip-all
public directory contents and include_files patterns.curl -I https://example.com/css/app.css).npm run build) by running them manually.use_streaming: true to reduce memory usage.paths to exclude deep routes.Exporter class.| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Crawling timeout | Partial export | Increase crawler.timeout in config. |
| Broken asset links | Non-functional static site | Validate include_files and asset paths. |
| Hook script failure | Deployment blocked | Add retries or fallback hooks. |
| Dynamic content in templates | Hardcoded data in static pages | Use @verbatim or static data sources. |
| Permission issues (export dir) | Export fails silently | Ensure write permissions to storage/app/export. |
config/export.php with common settings.How can I help you explore Laravel packages today?