How To Add Assetic to Symfony 2.8/3.0


Is assetic really bad ?!?

Posted by Pedro Resende on 01/12/2015 00:13

For those who have been using symfony since version 2.0, assetic has been a great help to keep css/js files inside your bundles and to help you to minify them. However, for some strange or insane reason, Fabien Potencier, the father of Symfony, decided that Assetic Bundle should be removed from symfony-standard package since Symfony is a PHP Backend framework and css/js are the responsibility of the FrontEnd developer and given that they should manage the css/js files in another way (grunt.js, gulp.js or npm)...

In my opinion this doesn't make any sense and given that I'll explain how to "install" assetic bundle into Symfony 2.8/3.0+.

Start by adding to composer.json the requirement of assetic-bundle and update the vendors

$ composer require symfony/assetic-bundle
$ composer update

After a while, you'll notice your vendors are updated. Now, lets add the Assetic bundle to AppKernel.

$ vi app/AppKernel.php

Inside the $bundles array add

new Symfony\Bundle\AsseticBundle\AsseticBundle(),

Now, to end you only need to add to config.yml

$ vi app/config/config.yml

the following

# Assetic Configuration
assetic:
   debug:          "%kernel.debug%"
   use_controller: false
   bundles:        [  ]
  #java: /usr/bin/java
  filters:
       cssrewrite: ~
       #closure:
       #    jar: "%kernel.root_dir%/Resources/java/compiler.jar"
       #yui_css:
       #    jar: "%kernel.root_dir%/Resources/java/yuicompressor-2.4.7.jar"

And that is it, you are good to go :)