32
Frontend asset management with BOWER AND GULP.JS

Frontend asset management with Bower and Gulp.js

Embed Size (px)

DESCRIPTION

Leverage Bower as your package manager for the front-end assets of your CakePHP application. Define your packages once (jQuery, Bootstrap, and what not?), and let it download everything for you and check for compatibilities among them. No more committing third-party assets to your repository. And also utilizing Gulp.js, the streaming build system, for automating repetitive front-end related tasks like converting LESS to CSS, CoffeeScript to JavaScript, concatenating files, minifying them, etc with just a single command.

Citation preview

Page 1: Frontend asset management with Bower and Gulp.js

Frontend asset management with

BOWER AND GULP.JS

Page 2: Frontend asset management with Bower and Gulp.js

@FAHAD19Also known as Fahad Ibnay HeylaalWorking with CakePHP since v1.1.Creator of @Croogo CMS (built on CakePHP)Bower Team MemberLikes JavaScript, loves CoffeeScriptNice guy (sic)

Page 3: Frontend asset management with Bower and Gulp.js

RENAN GONÇALVESUsing CakePHP since v1.1, joined Core Team on v1.2Developed Migrations plugin at CakeDCAutomate stuff at True.nl#cakephp in freenode as renan_saddam

Page 4: Frontend asset management with Bower and Gulp.js

BOWERA package manager for the web

http://bower.io

Page 5: Frontend asset management with Bower and Gulp.js

composergemnpm...now bower?

Page 6: Frontend asset management with Bower and Gulp.js

IT'S FOR THE BROWSER

Page 7: Frontend asset management with Bower and Gulp.js

THINK OF PACKAGES LIKE:jQueryTwitter BootstrapUnderscore.jsAngularJS

Page 8: Frontend asset management with Bower and Gulp.js

BUT WHY NOT JUST USENPM DIRECTLY?

Page 9: Frontend asset management with Bower and Gulp.js

LET'S TRY BOWER!

Page 10: Frontend asset management with Bower and Gulp.js

Install it with npm$ npm install --global bower

Page 11: Frontend asset management with Bower and Gulp.js

JSON FILEExpects a bower.json file in your project root.

Page 12: Frontend asset management with Bower and Gulp.js

BOWER.JSON{ "name": "my-cakephp-app", "version": "0.0.1", "dependencies": { "jquery": "1.9.x", "bootstrap": "2.3.x" }}

Page 13: Frontend asset management with Bower and Gulp.js

BUT WHERE WILL ITDOWNLOAD THE FILES?

Page 14: Frontend asset management with Bower and Gulp.js

ENTER .BOWERRC FILE

Page 15: Frontend asset management with Bower and Gulp.js

EXAMPLE .BOWERRC FILE{ "directory": "webroot/vendors"}

File located in the same directory as bower.json

Page 16: Frontend asset management with Bower and Gulp.js

Go to your app directory, and run:$ bower install

You will see all your packages being downloaded to webroot/vendors directory

Page 17: Frontend asset management with Bower and Gulp.js

QUESTIONS?For Bower?

Page 18: Frontend asset management with Bower and Gulp.js

GULPThe streaming build system

http://gulpjs.com

Page 19: Frontend asset management with Bower and Gulp.js

WHY?Automation. Mainly for your frontend development tasks.

Page 20: Frontend asset management with Bower and Gulp.js

HISTORYGrunt, Gulp, Broccoli, Cabbage

Page 21: Frontend asset management with Bower and Gulp.js

THINK OF REPITITIVE TASKS LIKE:Compiling LESS files (Bootstrap anyone?)Compiling CoffeeScriptLintingMinifying your assets...and more

Page 22: Frontend asset management with Bower and Gulp.js

LET'S TRY GULP!

Page 23: Frontend asset management with Bower and Gulp.js

Installing with NPM:$ npm init

$ npm install --save-dev gulp

$ npm install --global gulp

Page 24: Frontend asset management with Bower and Gulp.js

PACKAGE.JSONOur CakePHP app now have a package.json file:

{ "title": "My CakePHP Project", "name": "my-cakephp-project", "version": "0.0.1", "devDependencies": { "gulp": "~3.8.7" }}

Page 25: Frontend asset management with Bower and Gulp.js

GULPFILE.JSThis file contains all your Gulp tasks

var gulp = require('gulp');

gulp.task('default', function() { // place code for your default task here});

Page 26: Frontend asset management with Bower and Gulp.js

DEFINING TASKSvar gulp = require('gulp');

gulp.task('default', [ 'css', 'js']);

gulp.task('css', function() { // Compile CSS});

gulp.task('js', function() { // Compile JS});

Page 27: Frontend asset management with Bower and Gulp.js

RUN TASKS$ gulp default

Or for the default task, just:$ gulp

Page 28: Frontend asset management with Bower and Gulp.js

REAL WORLD EXAMPLE WITH LESS

Page 29: Frontend asset management with Bower and Gulp.js

DOWNLOAD THE GULP PLUGIN FOR LESS$ npm install --save-dev gulp-less

Page 30: Frontend asset management with Bower and Gulp.js

GULPFILE.JS WITH LESS TASKSvar less = require('gulp-less');

gulp.task('less', function () { gulp.src('./webroot/vendors/bootstrap/less/bootstrap.less') .pipe(less()) .pipe(gulp.dest('./webroot/ccss'));});

Page 31: Frontend asset management with Bower and Gulp.js

COMPILE TWITTER BOOTSTRAP$ gulp less

You now have a new file at webroot/css/bootstrap.css

Page 32: Frontend asset management with Bower and Gulp.js

THANK YOU!Questions?

Ping us on Twitter and !@renan_saddam @fahad19