Max Damage Max Damage - 5 months ago 79
Javascript Question

Using jQuery UI in Symfony2 through Composer. How do I publish assets from vendors directory?

In a Symfony 2.3 project I want to install jQuery UI using Composer. I found the package

components/jqueryui
available on packagist.com

The project is also using BraincraftedBootstrapBundle that loads jQuery (see Getting Started).

I have 2 problems with this configuration:


  1. I have no idea how to access in my Twig tempaltes the jQuery UI files that are located in
    vendors/components/jqueryui
    .

  2. How can I tell Composer that I don't want jQuery UI to require it's dependency
    components/jquery
    , since jQuery library is already installed by BraincraftedBootstrapBundle, under
    jquery/jquery
    or to tell BraincraftedBootstrapBundle to use jQuery from
    components/jquery
    .



Running
composer show -i | grep jquery
brings up this:

components/jquery 2.1.3 jQuery JavaScript Library
components/jqueryui 1.11.4 jQuery UI is a curated set of user interface interactions, effects, widgets, and themes built on top of the jQuery JavaScript Library. W...
jquery/jquery 1.11.2

Answer

There are multiple ways of doing this:

  1. you can define the vendor path for the file in your config.yml. files stay in the vendor folder.

  2. you can also define a components-dir (custom config directive for "components"):

    {
        "require": {
            "components/jquery":     "^2.0",
            "components/jqueryui":   "^1.11"
        },
        "config": {
            "component-dir": "web/assets"
        }
     }
    
  3. or you can trigger a custom install command and move the asset files from the vendor folder to your assets folder and then define this asset path.

  4. or you can use bower, executed as a postinstall command, to fetch and install the assets into a defined dir. https://github.com/bower/bower/tree/v0.3.0#bower-configuration