DEVELOPMENT by Pedro Resende

How To Add Assetic to Symfony 2.8/3.0

Is assetic really bad ?!?

Post by Pedro Resende on the 1 of December of 2015 at 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 :)