2

I use composer for PHP dependencies. I was under the impression that for front end dependencies I should use Bower. So, I installed Bower and loaded my FE dependencies (Bootstrap, jQuery) using that. I then manually symlink to the libraries as follows:

mypc:/var/www/myproject/public/js$ ls -l
total 8
lrwxrwxrwx 1 tom tom   67 Dec 23 07:29 bootstrap.min.js -> /var/www/myproject/bower_components/bootstrap/dist/js/bootstrap.min.js
lrwxrwxrwx 1 tom tom   58 Dec 23 07:29 jquery.min.js -> /var/www/myproject/bower_components/jquery/dist/jquery.min.js

However, I notice that these are stored within a directory /bower_components just as composer dependencies are stored in /vendor. So now I have /bower_components and /vendor as well as /node_modules (for grunt and grunt plugins). So as all Bower does it bring down the repositories, upon which I need to link to them - can I not just use composer for front end libraries too?

"components/jquery": "dev-master"
"components/bootstrap": "dev-master"

.. then create symlinks to the files (e.g. .js .css) in my public/* directories? Is there any reason whhy Bower is still better for managing FE dependencies? Thanks

  • This would only work of course if those front end libraries have a corresponding repo on packagist.org. – RibaldEddie Jan 1 '15 at 20:08
  • Just wait until you can't find a package on Bower and need to use npm also – Varedis Jan 8 '15 at 14:53
2

No Composer is a dependency manager for PHP only while Bower is optimized for front end dependencies that can be used with not only sites built with PHP but built with other programming languages and frameworks. I would stick with Bower for front end dependency management as that's what its designed for. :)

  • 1
    Even though it's true that Composer was created to manage PHP packages, it's interesting to note that some front-end frameworks are now installable via Composer, such as Foundation and Bootstrap. – Benjamin Mar 8 '16 at 16:05
6

I just stumbled across this gem that will allow you to use Composer with Bower packages:

https://github.com/francoispluchino/composer-asset-plugin

From their Readme:

The Composer Asset Plugin allows you to manage project assets (css, js, etc.) in your composer.json without installing NPM or Bower.

This plugin works by transposing package information from NPM or Bower to a compatible version for Composer. This allows you to manage asset dependencies in a PHP based project very easily.

Features include:
  • Works with native management system versions of VCS repository of composer
  • Works with public and private VCS repositories
  • Lazy loader of asset package definitions to improve performance
  • Import filter with the dependencies of the root package and the installed packages, for increased dramatically the performance for the update
  • Automatically get and create an Asset VCS repository defined in:
  • Automatically get and create the Asset VCS repositories of dependencies defined in each asset package (dev dependencies included)
  • Mapping conversion of asset package to composer package for:
  • Conversion of Semver version to the composer version
  • Conversion of Semver range version to the composer range version
  • Conversion of dependencies with URL to the composer dependencies with the creation of VCS repositories
  • Conversion of multiple versions of the same dependency to different dependencies of composer
  • Add manually the multiple versions of a same dependency in the project
  • Add a custom config of VCS Repository
  • Override the config of VCS Repository defined by the asset registry directly in extra section of root composer
  • VCS drivers for:
    • Git
    • GitHub (compatible with repository redirects)
    • Git Bitbucket
    • Mercurial
    • Mercurial Bitbucket
    • SVN
    • Perforce
  • Local cache system for:
    • package versions
    • package contents
    • repository redirects
  • Custom asset installers configurable in the root file composer.json
  • For Bower, all files defined in the section ignore will not be installed
  • Disable or replace the deleting of the ignore files for Bower
  • Enable manually the deleting of the ignore files for NPM
  • Use the Ignore Files Manager in the Composer scripts
  • Compatible with all commands, including:
    • depends
    • diagnose
    • licenses
    • remove
    • require
    • search (bower only)
    • show
    • status

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.