Pregunta

I have several projects that have libraries like jQuery and I must say it's getting pretty annoying having to copy the libraries manually to app/Resources/public in Symfony2. Not just this but any other library dependency or plugin.

The closest I got is this question: How to install jQuery with Composer? but this installs it under /vendor/ (which according to "best practices" it should be under something like app/Resources) then I tried using composer's installer-paths but also to no avail https://github.com/composer/composer/issues/2293.

What options are there left? Is there any way I can run composer.phar update/install and have jquery under Symfony2's app/Resources/public directory?

¿Fue útil?

Solución

I ended up using composer, works better than I thought!

//composer.json
//for dev
"require-dev": {
    "jquery/jquery-dev": "1.9.1-dev"
},
//or for production
"require": {
    "jquery/jquery": "1.9.1",
},
"repositories": [
{
    "type": "package",
    "package":
    {
        "name": "jquery/jquery",
        "version": "1.9.1",
        "dist":    
        {   
            "url": "http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js",
            "type": "file"
        }
    }
},
//Other 3rd party libraries
]

Then for twig something like:

{% block javascripts %}
    {% javascripts
        '%kernel.root_dir%/../vendor/jquery/jquery/jquery.min.js' //for production
        '%kernel.root_dir%/../vendor/jquery/jquery-dev/jquery.js' //or debugging
    %}
        <script type="text/javascript" src="{{ asset_url }}"></script>
    {% endjavascripts %}
{% endblock %}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top