Integrating Bower with Laravel
Not long ago I discovered Bower, a package manager for web resources such as CSS and JS. I used to copy/paste all the needed resources to each one of my projects. You know what I'm talking about here: downloading jQuery and Twitter Bootstrap all the time, copying them into the project folder, etc.. Enough of that crap. Bower enables you to automatically install those required resources and manage them as you may like in your development process.
Bower depends on Node and npm, so be sure you have those installed in your system before proceeding.
npm install -g bower
Now, in your Laravel project folder you should choose a folder where Bower is gonna put all the resources we want to install. I usually like to put it under the public folder. Let's create a folder named bower_resources under the public folder. Using your favorite editor or the command line you should create a file named .bowerrc in the root of your Laravel project. In this file you override the default directory where Bower installs all the resources:
{
"directory": "public/bower_resources"
}
Now Bower is able to save the dependencies whenever we install a resource. Using the bower install command and the -S flag, install the popular jQuery library:
bower install jquery -S
If you check your public/bower_resources you're gonna see a jquery folder with the library contents in it. Awesome right? Well there's much more. You can manage your dependencies for development and production environments. Check the Bower documentation to know more about all the possibilities Bower offers you.
Another cool thing is that we don't longer have to keep track of our resources in our code repository. We don't need to commit the public/bower_resources, we just need to commit .bowerrc and bower.json and when we run Bower the resources folder will be created and filled with all of our resources!
Enjoy!