- Can I use this polyfill bundle in Laravel, or is it only for Symfony?
- This bundle is Symfony-native but can work in Laravel with minor adjustments. You’ll need to install a Twig bridge (like `twig-bridge`) to enable Twig templating in Laravel, then configure routes and services to match Laravel’s syntax. The core polyfill logic remains compatible.
- How do I configure polyfills for my Laravel project?
- Create a YAML config file (e.g., `/frontend/polyfill/config.yaml`) by copying the `Resources/sample/config.yaml` from the bundle. Activate polyfills by setting `active: true` for each entry. Override the config path in your Laravel services configuration if needed.
- Will this bundle work with Laravel Mix or Vite for asset compilation?
- The bundle generates polyfill files dynamically, which may conflict with Laravel Mix/Vite’s static asset hashing. You can either serve polyfills on-demand via Laravel routes or extend your build process to pre-generate them during `npm run dev/prod`. Custom logic may be needed to integrate with `mix-manifest.json`.
- What Laravel versions does this bundle support?
- The bundle itself is Symfony-focused, but Laravel compatibility depends on your setup. It works with Laravel 8+ (for Twig bridge support) and later versions. Test thoroughly with your specific Laravel release, as some Symfony dependencies may require adjustments.
- How do I integrate Twig into Laravel for this bundle?
- Install the `twig-bridge` package and configure Twig in Laravel’s `config/app.php`. Register Twig services in `AppServiceProvider` and ensure your Blade templates can call Twig functions like `get_front_polyfill_list()`. Alternatively, manually replicate Twig logic in Blade if you prefer not to use Twig.
- Can I customize the polyfill output format (e.g., JSON, array, or custom properties)?
- Yes, the bundle supports customizing the output format. Use `get_front_polyfill_list('js', 'customKey1', 'customKey2')` in Twig to rename properties in the generated JavaScript array. This lets you structure the output to fit your frontend framework’s needs.
- How are polyfill files cached in Laravel, and can I use Redis or file caching?
- The bundle relies on Symfony’s cache system, which may not map directly to Laravel’s cache drivers. You’ll need to manually handle caching in Laravel, such as storing generated polyfill files in Redis or the filesystem and invalidating them via Laravel’s cache system when configs change.
- What happens if a requested polyfill file is missing or fails to generate?
- The bundle doesn’t include built-in fallback logic for missing polyfills. You’ll need to handle 404 routes in Laravel (e.g., return a default polyfill file or a client-side fallback script) or ensure your YAML config always includes a valid polyfill list.
- Are the polyfill tests (e.g., `test1`, `test2`) compatible with Laravel’s testing tools like Pest or PHPUnit?
- The tests are static and designed for frontend feature detection (e.g., `IntersectionObserver`). They can run in Laravel, but you may need to wrap them in Laravel’s testing environment or mock them if they rely on browser APIs. No direct integration exists, but they’re simple enough to adapt.
- What are the alternatives to this bundle for Laravel polyfill generation?
- For Laravel, consider using standalone polyfill libraries like `core-js` or `polyfill-service` with custom routes, or packages like `laravel-mix-polyfills` for Mix/Vite integration. These avoid Twig dependencies but offer less dynamic configuration. The `front-polyfill-bundle` is unique for its YAML-driven, Twig-based approach.