GDG Kraków - Intro to front-end automation using bower.js & grunt.js

28
Into the parrots & boars world INTRODUCTION TO FRONT-END AUTOMATION

description

Presentation from GDG Kraków front-end meetup presenting concepts of bower.js & grunt.js.

Transcript of GDG Kraków - Intro to front-end automation using bower.js & grunt.js

Page 1: GDG Kraków - Intro to front-end automation using bower.js & grunt.js

Into theparrots & boars

world

INTRODUCTION TO FRONT-END AUTOMATION

Page 2: GDG Kraków - Intro to front-end automation using bower.js & grunt.js

Hi! I’m Dominik

FE/UX focused web dev @ Making Waves

Engaged into projects for FIFA

A little bit of a control freak

Baking&cooking in between

Page 3: GDG Kraków - Intro to front-end automation using bower.js & grunt.js

1. Motivation

2. Tools required

3. Part I - The Ingredients

4. Part II - The Recipes

5. Live example

Agenda

Page 4: GDG Kraków - Intro to front-end automation using bower.js & grunt.js

Motivation

Page 5: GDG Kraków - Intro to front-end automation using bower.js & grunt.js

Tools required

Ruby, SASS, Stylus, nib, #younameit

Page 6: GDG Kraków - Intro to front-end automation using bower.js & grunt.js

PART I

The Ingredients

Page 7: GDG Kraków - Intro to front-end automation using bower.js & grunt.js

bower.jsFRONT-END PACKAGE MANAGEMENT

Page 8: GDG Kraków - Intro to front-end automation using bower.js & grunt.js

General information

• Download

• Manage

• Share

Page 9: GDG Kraków - Intro to front-end automation using bower.js & grunt.js

Setup & usage

• npm install –g bower

• bower.json

Hint: use bower init to bootstrap bower.json file

Page 10: GDG Kraków - Intro to front-end automation using bower.js & grunt.js

bower.jsonPROJECT METADATA & DEPENDENCY MANAGEMENT

{‘name’ : ‘project name’,‘version’ : ‘project version’,‘dependencies’ : {

‘package-name’ : ‘package version’},‘devDependencies’ : {

‘package-name’ : ‘package version’,‘package-name’ : ‘package version’

}

}

Page 11: GDG Kraków - Intro to front-end automation using bower.js & grunt.js

Bower commands

• bower search <package name>

• bower install <package name>#<package version>

• bower install --save-dev <package name>#<package version>

Detailed package versioning info: https://www.npmjs.org/doc/json.html#dependencies

Page 12: GDG Kraków - Intro to front-end automation using bower.js & grunt.js

So… how to use bower.js?

Page 13: GDG Kraków - Intro to front-end automation using bower.js & grunt.js

.bowerrcGENERAL BOWER CONFIGURATION

{‘directory’ : ‘packages dir’,

}

Detailed bower specs: http://bit.ly/1aJGFf8

Page 14: GDG Kraków - Intro to front-end automation using bower.js & grunt.js

PART I

The Ingredients - yay, we got it!

Page 15: GDG Kraków - Intro to front-end automation using bower.js & grunt.js

PART II

The Recipes

Page 16: GDG Kraków - Intro to front-end automation using bower.js & grunt.js

grunt.jsFRONT-END TASK AUTOMATION

Page 17: GDG Kraków - Intro to front-end automation using bower.js & grunt.js

Task automation

• watching files for changes & live reload

• CSS/JS linting, minification

• CSS preprocessors compilation

• JS unit tests running

• HTML processing

• … and many many other boring tasks

Page 18: GDG Kraków - Intro to front-end automation using bower.js & grunt.js

Setup

• npm install –g grunt-cli

• package.json

• Gruntfile.js

Page 19: GDG Kraków - Intro to front-end automation using bower.js & grunt.js

What grunt-cli is?

grunt-cli

Project Ausing grunt v. X

Project Busing grunt v. Y

Page 20: GDG Kraków - Intro to front-end automation using bower.js & grunt.js

Project setup

• package.json

• Gruntfile.js

Page 21: GDG Kraków - Intro to front-end automation using bower.js & grunt.js

package.jsonPROJECT METADATA & GRUNT PLUGINS MANAGEMENT

{‘name’ : ‘project name’,‘version’ : ‘project version’,‘devDependencies’ : {

‘package-name’ : ‘package version’}

}

Hint: use npm init to create & preconfigure package.json

Useful commands

npm init

npm install <package>

npm install <package> --save-dev

Page 22: GDG Kraków - Intro to front-end automation using bower.js & grunt.js

Let’s see it in action

Page 23: GDG Kraków - Intro to front-end automation using bower.js & grunt.js

Gruntfile.jsGENERAL STRUCTURE

module.export = function(grunt) {

grunt.initConfig({‘pkg’ : grunt.file.readJSON(’package.json’),taskName : {

task configuration}

});

grunt.loadNpmTask(’plugin-name’);

grunt.registerTask(’complexTask’, [’taskName1’,’taskName2’,…]);

}

Page 24: GDG Kraków - Intro to front-end automation using bower.js & grunt.js

Gruntfile.js

grunt.initConfig({‘pkg’ : grunt.file.readJSON(’package.json’),taskName : {

targetName : { options: {

task options},src: ’files to be processed’,dest:’output files’

}}

});

grunt.loadNpmTask(’grunt-contrib-taskName’);

TASK DEFINITION & CONFIGURATION

Page 25: GDG Kraków - Intro to front-end automation using bower.js & grunt.js

Gruntfile.jsTASK EXECUTION

grunt taskName:taskTarget

Page 26: GDG Kraków - Intro to front-end automation using bower.js & grunt.js

Gruntfile.jsTASK CONFIGURATION – FILES MAPPING

Compact version

taskName : {targetName : {

options: {task options

},src: ’input files’,dest:’output file’

}}

Object version

taskName : {targetName : {

options: {task options

},files: {

’output file1’:[’input file1’,…],’output file2’:[’input fileX’,…]

}}

}

Page 27: GDG Kraków - Intro to front-end automation using bower.js & grunt.js

Let’s bake!

Page 28: GDG Kraków - Intro to front-end automation using bower.js & grunt.js

Thanks

@prokopddprokop @ github

blog.makingwaves.com