agallou/grunt-hash-assets-bundle
Symfony bundle adding a Twig grunt_asset() function to reference files renamed by grunt-hash (e.g., main.54e79f6f.css). Looks up matching hashed assets in web/assets and returns the correct /assets URL; throws if missing or ambiguous.
main.54e79f6f.css). This is critical for performance optimization in Laravel/PHP applications with static assets.symfony/twig-bridge).npm/yarn support mitigates this but introduces a dual-build-system (PHP + JS).grunt_asset() functionality, as Blade doesn’t natively support Twig functions.grunt watch). Laravel’s mix or vite could conflict if both systems generate hashed filenames.main*.css).mix/vite (which natively supports hashing) suffice?grunt_asset() be exposed in Blade templates? Custom helper or Twig bridge?npm run dev/prod)?symfony/twig-bridge). For Blade, requires a custom solution (e.g., a Blade directive or helper wrapping the Twig function).mix/vite may be simpler.web/assets/ with a predictable naming pattern (e.g., main.css → main.[hash].css).laravel-mix, vite, or manual concatenation).postcss or npm run build scripts).asset_hash()) that calls the Twig function via a service container bridge.// app/Helpers/AssetHelper.php
function asset_hash(string $path): string {
return app('twig')->createTemplate("{{ grunt_asset('$path') }}")->render();
}
npm run grunt before npm run prod).mix to avoid hashing if Grunt handles it (or vice versa).web/assets/; adjust assets_dir and assets_base_path for custom paths.Cache-Control: immutable).grunt watch).grunt-hash-assets-bundle config may diverge from Laravel’s asset pipeline if not synchronized.async for large asset directories.| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Grunt build fails | Broken asset links | Add pre-build validation in CI/CD. |
| Missing hashed file | 500 error in Twig | Fallback to unhashed path in dev mode. |
| Duplicate hashed files | Random asset selection | Validate file uniqueness in Grunt config. |
| CDN cache mismatch | Stale assets served | Use Cache-Control: no-cache in dev. |
| Node.js/Grunt dependency conflicts | Build pipeline breaks | Containerize Grunt (e.g., Docker) for isolation. |
How can I help you explore Laravel packages today?