Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Export Laravel Package

spatie/laravel-export

Export a Laravel app as a static site bundle. Crawls your routes to generate HTML for every URL and copies your public assets into an export folder, ready to upload to Netlify or any static host—keep Laravel tools locally while deploying static.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Static Site Generation (SSG) Use Case: The package excels in converting Laravel applications into static HTML bundles, making it ideal for projects requiring static hosting (e.g., blogs, marketing sites, documentation) while retaining Laravel’s dynamic backend for content management (e.g., Nova/Filament).
  • Hybrid CMS Workflow: Enables a decoupled architecture where dynamic content is managed via Laravel (e.g., database-driven admin panels) while the frontend is statically exported for performance and scalability.
  • Asset Handling: Automatically includes the public directory (CSS, JS, images), ensuring assets are bundled without manual intervention.
  • Limitations:
    • No real-time updates: Static exports require manual re-generation (e.g., via php artisan export) or CI/CD triggers.
    • Dynamic content constraints: Features relying on server-side rendering (e.g., user-specific content, sessions) must be pre-rendered or excluded.
    • SEO/Performance: While static, the package doesn’t natively support advanced SSG features like incremental builds or ISR (Incremental Static Regeneration).

Integration Feasibility

  • Laravel-Centric: Designed for Laravel, with minimal friction for existing projects (e.g., no major framework changes required).
  • Dependency Lightweight: Only requires Laravel and PHP, with no heavy external dependencies.
  • Customization Hooks: Supports overriding default behavior (e.g., URL crawling rules, asset handling) via service providers or config.
  • Potential Conflicts:
    • Middleware/Route Constraints: Dynamic routes (e.g., authenticated endpoints) may need exclusion or pre-rendering.
    • Asset Pipeline: If using Laravel Mix/Vite, ensure static assets are compiled before export.
    • Database-Dependent Views: Views relying on runtime DB queries (e.g., user-specific data) must be mocked or pre-fetched.

Technical Risk

  • Crawling Logic: The package’s URL discovery mechanism (e.g., Route::get()) may miss or incorrectly crawl routes with complex constraints (e.g., API routes, locale prefixes).
    • Mitigation: Test with a representative route list; use export:ignore to exclude non-static routes.
  • Asset Versioning: Static assets (e.g., hashed filenames) may break if not handled consistently between dev and export environments.
    • Mitigation: Use mix-manifest.json or Vite’s asset manifest to ensure correct paths.
  • Performance at Scale: Large sites with thousands of routes may experience slow export times or high memory usage.
    • Mitigation: Test with a staging environment; consider parallelizing exports or splitting into sub-bundles.
  • SEO/Metadata: Dynamic meta tags (e.g., OpenGraph) may not render correctly without server-side logic.
    • Mitigation: Pre-render critical pages or use a headless CMS for metadata.

Key Questions

  1. Use Case Clarity:
    • Is the primary goal static hosting (e.g., Netlify/Vercel) or hybrid dynamic/static (e.g., CMS + static frontend)?
    • Are there real-time requirements (e.g., user-specific content) that conflict with static exports?
  2. Content Management:
    • How will content be updated? (Manual php artisan export vs. automated CI/CD?)
    • Is there a fallback for dynamic content (e.g., edge functions, client-side hydration)?
  3. Asset Pipeline:
    • Are assets (CSS/JS) built for production before export? How are versioned paths handled?
  4. Scalability:
    • What is the expected number of routes/pages? Are there performance benchmarks for similar-sized sites?
  5. Deployment Workflow:
    • How will exports be triggered? (e.g., post-deploy hook, cron job, GitHub Actions)
    • Is there a rollback strategy if an export fails or introduces bugs?
  6. SEO/Analytics:
    • How will dynamic metadata (e.g., canonical URLs, structured data) be managed?
    • Are there plans for incremental exports (e.g., only re-exporting changed pages)?

Integration Approach

Stack Fit

  • Laravel Ecosystem: Native compatibility with Laravel’s routing, views, and asset pipelines. Works seamlessly with:
    • Admin Panels: Nova, Filament, Wink, or custom backends for content management.
    • Frontend Tools: Laravel Mix, Vite, or Inertia.js (for hybrid SPAs).
    • Hosting: Static hosts (Netlify, Vercel, Cloudflare Pages) or traditional PHP servers (with static files served via Nginx/Apache).
  • Non-Laravel Considerations:
    • PHP Version: Requires PHP 8.0+ (check compatibility with existing stack).
    • Database: No direct dependency, but views may rely on DB data (see "Dynamic Content" below).
    • Caching: Static exports bypass Laravel’s cache; ensure no critical logic relies on cached views.

Migration Path

  1. Assessment Phase:
    • Audit routes/views to identify static vs. dynamic content.
    • Test crawling logic with php artisan export:test (if available) or manually inspect generated files.
  2. Configuration:
    • Publish and customize the package config (php artisan vendor:publish --provider="Spatie\Export\ExportServiceProvider").
    • Define export:ignore rules for non-static routes (e.g., /admin, API endpoints).
  3. Asset Pipeline:
    • Ensure assets are built for production (npm run build or vite build).
    • Verify asset paths in exported HTML (e.g., no /public/ prefix leaks).
  4. Dynamic Content Handling:
    • Mock or pre-fetch data for views requiring runtime DB queries.
    • Use static placeholders for user-specific content (e.g., [USER_NAME]).
  5. Testing:
    • Validate exported HTML/CSS/JS locally and in staging.
    • Check for broken links, missing assets, or incorrect meta tags.
  6. CI/CD Integration:
    • Add export step to deployment pipeline (e.g., post-merge to main):
      # Example GitHub Actions step
      - name: Export static site
        run: php artisan export
      - name: Deploy to Netlify
        uses: nwtgck/actions-netlify@v1.2
        with:
          publish-dir: './export'
      

Compatibility

  • Laravel Versions: Tested with Laravel 9+ (check composer.json for exact range).
  • Route Constraints: May require adjustments for:
    • Named routes: Ensure Route::get('blog/{post}', ...) is crawlable.
    • Middleware: Exclude routes with auth, guest, or locale middleware.
    • API Routes: Prefix with api/ and ignore in config.
  • View Engines: Primarily tested with Blade; custom engines may need adaptation.
  • Third-Party Packages:
    • SEO Packages: Ensure meta tags (e.g., from spatie/laravel-seo) render correctly.
    • Authentication: Static exports won’t include sessions; use client-side auth (e.g., JWT) if needed.

Sequencing

  1. Phase 1: Proof of Concept
    • Export a small subset of routes (e.g., blog posts).
    • Verify assets, links, and metadata.
  2. Phase 2: Full Export
    • Gradually include more routes, monitoring performance.
    • Automate exports in a staging environment.
  3. Phase 3: Deployment
    • Integrate with hosting provider (e.g., Netlify’s netlify.toml):
      [build]
      publish = "export"
      command = "php artisan export"
      
    • Set up monitoring for export failures (e.g., Slack alerts).
  4. Phase 4: Optimization
    • Implement incremental exports (e.g., only re-export changed pages).
    • Cache exports to reduce build times.

Operational Impact

Maintenance

  • Package Updates:
    • Monitor spatie/laravel-export for breaking changes (MIT license allows forks if needed).
    • Update dependencies via composer update spatie/laravel-export.
  • Configuration Drift:
    • Maintain a config/export.php backup for rollbacks.
    • Document ignored routes and custom crawlers.
  • Asset Management:
    • Ensure public/ directory is excluded from version control (if using Git) or managed via deployment.
    • Update asset pipelines (e.g., Mix/Vite) to avoid path conflicts.

Support

  • Troubleshooting:
    • Common issues:
      • Broken links: Verify url() helper uses absolute paths in Blade.
      • Missing assets: Check public/ directory is copied to export/ during build.
      • Crawling errors: Debug with php artisan export:test or inspect the crawler’s route list.
    • Logs: Enable Laravel logging to capture export errors.
  • Community Resources:
    • GitHub Issues/Discussions for package-specific problems.
    • Laravel forums for integration challenges (e.g., Filament/Nova compatibility
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport