thatguy thatguy - 6 months ago 33
PHP Question

How do you use a build system like gulp.js with dependency managers like bower

After years of being poor - mediocre PHP developer, I decided to up my game and learn a little more about modern workflows and best practice for developing web apps.

I've studied up on task runners, dependency managers, git, and cloud servers. I'm working on a PC predominantly and I've decided to settle with


  • PHP and Bootstrap 3 for front end work

  • MYSQL (NoSQL seemed like overkill for what I need)

  • AppFog for cloud hosting with git for repository control

  • gulp.js for task automation - it seemed far simpler than grunt for PHP projects

  • either bower or composer for dependency management (still can't decide)



I used some of the answers on here to work out how to change the location bower, for example, places the files it downloads but I'm struggling to understand what the best practice is when you use a dependency manager (that seems to download a whole git repo) and a task runner.

For example I can tell bower to download jquery or bootstrap into the src/vendor folder but what gets downloaded is a mix of javascript, css and other files. I could leave them there and reference them in my code but then running a gulp process would involve cherry picking individual files and minimizing or concatenating one by one, avoiding all the other stuff in the folder that I don't need.

Is this best practice for handling this or am I in the wrong ball park. Should I even be using a task runner with a dependency manager?

Answer

Look at globbing in Gulp. You should be able to pick out your CSS and JS by using gulp.src('src/vendor/**/*.css') and gulp.src('src/vendor/**/*.js') respectively.

Alternatively, a quick search of NPM returns this which could be of some use: https://www.npmjs.org/package/gulp-bower-files/