miguel/assetic-angular-js-bundle
Integrates AngularJS asset files with the Assetic pipeline, letting PHP applications bundle, filter, and serve Angular scripts through a single configurable bundle rather than manual includes. A small legacy package best suited to older projects already built on Assetic.
Confirm your stack first: this bundle is only useful on a Symfony 2.x/3.x application that still uses AsseticBundle and AngularJS 1.x. Symfony no longer ships Assetic, so you almost certainly need symfony/assetic-bundle installed alongside this package.
composer require miguel/assetic-angular-js-bundle
Register the bundle in your kernel (app/AppKernel.php on legacy Symfony):
new MiguelGonzalez\AsseticAngularJsBundle\AsseticAngularJsBundle(),
Then enable the filter in app/config/config.yml under assetic.filters. The exact filter key and its options (module name, output wrapping) live in the bundle's DependencyInjection/ extension and Resources/config/ — read those first rather than guessing. You can also discover the registered filter name directly:
php app/console debug:container --tag=assetic.filter
A first working use case — compile every partial in a directory into a single JS file that primes the AngularJS template cache:
{% javascripts
'@AcmeBundle/Resources/views/partials/*.html'
filter='angular_template_cache'
output='js/templates.js' %}
<script src="{{ asset_url }}"></script>
{% endjavascripts %}
The output is JavaScript that calls $templateCache.put('<key>', '<html>') for each file. Once loaded, templateUrl lookups for those keys resolve synchronously and stop generating HTTP requests.
Directory-per-feature compilation. Point the javascripts tag at a glob, one tag per feature area (e.g. partials/admin/*.html, partials/shop/*.html). This keeps the cache file small per route and avoids rebuilding a giant bundle on every template edit. Combine them into a single output only when you have confirmed the total size is acceptable.
Match the cache key to templateUrl exactly. The filter derives a key from the file path; your templateUrl values (or ui-router state templateUrls) must use the same string character-for-character. If the filter emits keys relative to the bundle root, define a small templateUrl helper in your app that normalizes paths to that same form rather than hard-coding strings in both places.
Filter ordering matters. Apply the Angular template-cache filter before uglifyjs/uglifyjs2, not after. The cache filter produces valid JS around raw HTML strings; running a JS compressor first will mangle the HTML before it is wrapped, and running the cache filter after compression on .html inputs produces nothing useful. Keep the order explicit in the filter argument: filter='angular_template_cache,uglifyjs2'.
Dev vs. prod. In config_dev.yml use assetic.use_controller: true so templates are recompiled on every request while you edit partials. In config_prod.yml use false and run assetic:dump as part of deploy/cache:warmup. Verify the dumped file actually lands under web/js/ and is referenced via asset_url.
Module registration. The generated JS registers on a module (the bundle's configured module name). Ensure that module exists and is loaded before your app bootstraps, or that your app module declares it as a dependency. If you see templates missing at runtime, check this before blaming the filter.
Separate vendor vs. app templates. You rarely want third-party partials in the same cache file; scope globs to your own bundle's partials/ directory.
</script>-style strings are the classic source of broken generated JS.<script> or apostrophes in text, test the compiled output in a browser, not just in PHP. Pre-minifying HTML (before the cache filter) can reduce escaping edge cases../, absolute paths, and Windows/Unix separators can all leak into cache keys. Dump templates.js and grep the put( calls; that is the fastest way to confirm the keys match your templateUrls.asset_url handles versioning; a hand-written <script src="/js/templates.js"> will serve stale caches after deploy. Always go through asset_url.php app/console assetic:dump --watch recompiles on change and is far faster to debug than toggling use_controller and refreshing.apply_to pattern (if configured) and that the glob actually matches files — Assetic silently emits an empty file if the glob matches nothing. Compare source and output file counts.templateUrl function instead of string keys), implement Assetic's Assetic\Filter\FilterInterface with a small wrapper rather than patching the vendor bundle. This keeps upgrades/removals clean.angular-templatecache-style plugin, or replacing templateUrl with inline template: strings. Either eliminates the Assetic dependency entirely.How can I help you explore Laravel packages today?