Saturday, November 10, 2012

Managing js vendors and symfony 2.1.x

In my preveous post I've described how to manage js vendors in symfony2. However that solution is only applicable for version 2.0.x of symfony. In this post I'll describe how to manage js vendors in 2.1.x.

The idea is the same: load js vendors via symfony's standard mechanism (composer). But load into the folder under web directory.

Solution 1. Use ugly names

Again I will use as an example of js vendor.
Open your composer.json file and add the following line
"../web/vendor/extjs/ux/listbox": "master"
to the require array.

Naming repo in such a way will make composer load vendor scripts under /.../your-symfony-app/web/ directory and therefore this scripts will be exposed to browser.
Now all you have to do is add repositories to composer.json:
Now run php composer.phar update and check web/vendor folder if everything loaded ok.

If this solution looks like a hack to you check out the next solution.

Solution 2. Use scripts to make symlink

Add line
"js-vendors/extjs/ux/listbox": "master"
to the require array of the composer.json file.

add repositories:
Then add the following line to "post-update-cmd" array:
After running php composer.phar update there will be symlink created in web folder referring to vendor/js-vendors directory (however under linux only. For windows you will have to use windows' command for creating symlink).

P.S. Don't forget to add web/vendor into .gitignore

P.P.S. This is how my composer.json looks:


  1. Why not to use target-dir directive inside composer.json?

    1. Because target-tir works only for subfolders of the vendor folder. You just can't specify ../web/something as target-dir. Correct me if I am wrong.