zenstruck / asset-manifest-bundle
Loads an asset manifest to map your assets to dynamic ones.
Fund package maintenance!
kbond
Installs: 10 617
Dependents: 0
Suggesters: 0
Security: 0
Stars: 8
Watchers: 3
Forks: 1
Open Issues: 0
Type:symfony-bundle
Requires
- symfony/asset: ^2.8|^3.0
- symfony/framework-bundle: ^2.8|^3.0
- symfony/twig-bundle: ^2.8|^3.0
- twig/twig: ^1.26|^2.0
Requires (Dev)
- symfony/browser-kit: ^2.8|^3.0
- symfony/css-selector: ^2.8|^3.0
- symfony/finder: ^2.8|^3.0
This package is not auto-updated.
Last update: 2022-02-01 12:57:36 UTC
README
NOTE: This functionality of this bundle is now in Symfony Core.
ZenstruckAssetManifestBundle
This bundle adds the twig function manifest_asset
that is a wrapper for the native asset
but looks for a configured manifest json file to map assets. This file can be generated using
Gulp and the gulp-rev Gulp plugin.
If you have used Laravel with Laravel Elixir
the manifest_asset
function is similar to Laravel's elixir
function.
Installation
Download:
composer require zenstruck/asset-manifest-bundle
Enabled bundle:
//app/AppKernel.php //... public function registerBundles() { $bundles = [ //... new Zenstruck\AssetManifestBundle\ZenstruckAssetManifestBundle(), //... ]; //... } //...
Configuration
By default, no manifest is configured. In development, this is probably ideal. For production, you will want to configure a manifest file to map your assets.
#app/config/config_prod.yml #... zenstruck_asset_manifest: manifest_file: "%kernel.root_dir%/../web/assets/manifest.json" #...
Usage
asset
should be replaced by manifest_asset
in twig files.
Here an example:
<!DOCTYPE html> <html> <head> <title>My page title</title> <meta charset="utf-8"> <link rel="stylesheet" href="{{ manifest_asset('assets/main.css') }}"> </head> <body> My page content </body> </html>
Note: If no manifest file is configured, the manifest_asset
behaves exactly like the native
asset
function.
Prefixes
Say your public (web) folder looks as follows:
.
├── assets
│ ├── build
│ │ ├── css
│ │ │ └── app-8f07f52635.css
│ │ └── rev-manifest.json
│ └── css
│ └── app.css
And your rev-manifest.json
file looks as follows:
{ "css/app.css": "css/app-8f07f52635.css" }
Using the manifest_asset
twig function, you would pass assets/css/app.css
but this wouldn't map
correctly. To fix this, you can add prefixes to your config.yml
:
zenstruck_asset_manifest: manifest_file: "%kernel.root_dir%/../web/assets/build/manifest.json" prefix: source: assets/ destination: assets/build/
Now, assets/css/app.css
would properly map to assets/build/css/app-8f07f52635.css
.
Full Default Config
zenstruck_asset_manifest: manifest_file: ~ prefix: source: ~ destination: ~