Slide 1

Slide 1 text

Automate your front-end workflow with grunt.js

Slide 2

Slide 2 text

About this This talk is about workflow patterns using Grunt reinvent your work, love JS more make your life easier

Slide 3

Slide 3 text

Who Dimitris Tsironis Front-end Engineer at Splunk (ex-Bugsense) ! passionate about bringing BigData to the masses, eating bacon & geeing around

Slide 4

Slide 4 text

First, a story from good ol’ days

Slide 5

Slide 5 text

Slide 6

Slide 6 text

Slide 7

Slide 7 text

Now

Slide 8

Slide 8 text

Now

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

*cough* *cough*

Slide 13

Slide 13 text

Problem typical js file, named stuff.js

Slide 14

Slide 14 text

grunt is a task-based command line build tool for JavaScript projects

Slide 15

Slide 15 text

Grunt.js is used for Concatenation Testing with headless browsers JS linting basically, whatever

Slide 16

Slide 16 text

Installation $ npm install -g grunt-cli Install the grunt cli tool

Slide 17

Slide 17 text

Installation Edit your package.json file { "name": "my-project-name", "version": "0.1.0", "devDependencies": { "grunt": "~0.4.2", "grunt-contrib-jshint": "~0.6.3" } } grunt.loadNpmTasks(‘grunt-contrib-uglify'); Then in your Gruntfile.js add

Slide 18

Slide 18 text

Gruntfile.js module.exports = function(grunt) { ! // Project configuration. grunt.initConfig({ pkg: grunt.file.readJSON('package.json'), uglify: { options: { banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n' }, build: { src: 'src/<%= pkg.name %>.js', dest: 'build/<%= pkg.name %>.min.js' } } }); ! // Load the plugin that provides the "uglify" task. grunt.loadNpmTasks('grunt-contrib-uglify'); ! // Default task(s). grunt.registerTask('default', ['uglify']); ! };

Slide 19

Slide 19 text

Concatenating module: grunt-contrib-concat concat: { ‘assets/js/main.js’: [ ‘js/libs/jquery.js’, ‘js/libs/underscore.js’ ‘js/libs/backbone.js, ‘js/src/app.js’], ‘assets/css/style.css’: [ ‘css/bootstrap.css’, ‘css/main.css’] }

Slide 20

Slide 20 text

Compiling LESS module: grunt-contrib-less less: { dashboard: { files: { "css/main.css": "less/style.less", "css/landing.css": "less/landing.less", } } }

Slide 21

Slide 21 text

Running specs #1 module: grunt-contrib-jasmine jasmine: { src: [ 'specs/project.js'], options: { host: 'http://localhost:7000/', vendor: [ ‘libs/jquery.js’], helpers: [ 'specs/jasmine-jquery/lib/jasmine-jquery.js', ‘specs/bower_components/sinonjs/sinon.js' ], template: 'specs/index.tmpl', specs: 'specs/build/specs.js', keepRunner: true } },

Slide 22

Slide 22 text

Running specs #2 module: grunt-contrib-connect connect: { server: { options: { port: 7000 } } } grunt.registerTask('specs', ['connect', 'jasmine']); Registering our custom “specs” tasks

Slide 23

Slide 23 text

Watching files module: grunt-contrib-watch watch: { gruntfile: { files: '<%= jshint.gruntfile.src %>', tasks: ['jshint:gruntfile', 'concat', 'less'] }, less: { files: “less/**/*.less”, /* or use an array */ tasks: [‘less’, ‘concat’] }, specs: { files: “specs/**/*Specs.js” tasks: [‘specs’] } }

Slide 24

Slide 24 text

Live reload module: grunt-reload reload: { port: 6001, proxy: { host: 'localhost' } }, watch: { less: { files: “less/**/*.less”, /* or use an array */ tasks: [‘less’, ‘concat’, ‘reload’] } }

Slide 25

Slide 25 text

bower a package manager for the web

Slide 26

Slide 26 text

Installation $ npm install -g bower Install the bower tool

Slide 27

Slide 27 text

Usage $ bower install Install the bower tool $ bower install # or just install dependencies from bower.json $ bower install

Slide 28

Slide 28 text

Search $ bower search Search the packages

Slide 29

Slide 29 text

/etc/ $ bower help Help is always provided

Slide 30

Slide 30 text

Defining a new package $ bower init { "name": "my-project", "version": "1.0.0", "main": "path/to/main.css", "ignore": [ ".jshintrc", "**/*.txt" ], "dependencies": { "": "" }, "devDependencies": { "": "" } }

Slide 31

Slide 31 text

Registering a package $ bower register a valid manifest JSON Git tags (using semver) be available at a Git endpoint (e.g., GitHub); remember to push your Git tags!

Slide 32

Slide 32 text

Bugsense.js plugin (see Gruntfile.js & bower.json) Addy Osmani presentation Grunt plugins Bower homepage (incl. Yeomann) Grunt homepage

Slide 33

Slide 33 text

Thanks! twitter @tsironakos github @tsironis