2017 © Pedro Pelรกez
 

symfony-bundle asset-manifest-bundle

Loads an asset manifest to map your assets to dynamic ones.

image

zenstruck/asset-manifest-bundle

Loads an asset manifest to map your assets to dynamic ones.

  • Wednesday, November 29, 2017
  • by kbond
  • Repository
  • 2 Watchers
  • 6 Stars
  • 1,857 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 4 Versions
  • 12 % Grown

The README.md

NOTE: This functionality of this bundle is now in Symfony Core., (*1)

ZenstruckAssetManifestBundle

Build Status Scrutinizer Code Quality Code Coverage SensioLabs Insight StyleCI Latest Stable Version License, (*2)

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., (*3)

Installation

Download:, (*4)

composer require zenstruck/asset-manifest-bundle

Enabled bundle:, (*5)

//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., (*6)

#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., (*7)

Here an example:, (*8)

<!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., (*9)

Prefixes

Say your public (web) folder looks as follows:, (*10)

.
โ”œโ”€โ”€ assets
โ”‚ย ย  โ”œโ”€โ”€ build
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ css
โ”‚ย ย  โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ app-8f07f52635.css
โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ rev-manifest.json
โ”‚ย ย  โ””โ”€โ”€ css
โ”‚ย ย      โ””โ”€โ”€ app.css

And your rev-manifest.json file looks as follows:, (*11)

{
    "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:, (*12)

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., (*13)

Full Default Config

zenstruck_asset_manifest:
    manifest_file: ~
    prefix:
        source: ~
        destination: ~

The Versions

11/11 2016
02/06 2016

v1.0.0

1.0.0.0 http://zenstruck.com/project/ZenstruckAssetManifestBundle

Loads an asset manifest to map your assets to dynamic ones.

  Sources   Download

MIT

The Requires

 

The Development Requires

twig css frontend grunt javascript asset gulp