Slide 1

Slide 1 text

Automate your frontend, bitch!

Slide 2

Slide 2 text

EL BACKEND ESCALA Reparte a ~100 usuarios

Slide 3

Slide 3 text

Deliver to ~100 users Reparte a ~1m usuarios EL BACKEND ESCALA

Slide 4

Slide 4 text

Y TAMBIÉN LO HACE EL FRONTEND Deliver to ~100 users Deliver to ~1m users

Slide 5

Slide 5 text

MANERAS DE MEJORAR TU FRONTEND pre-procesadores CSS: LESS, Sass, Stylus… lenguajes compila-a-js: Coffeescript, Typescript, Clojurescript… frameworks en el cliente: AngularJS, Backbone.js, Ember.js… frameworks CSS: Bootstrap, Pure, UIKit, tuktuk…

Slide 6

Slide 6 text

Y TODAS ELLAS TIENEN EN COMÚN…

Slide 7

Slide 7 text

POR QUÉ UN LANZADOR DE TAREAS? AUTOMATIZACIÓN

Slide 8

Slide 8 text

QUÉ TIENE GRUNT DE BUENO? gran ecosistema que crece cada día JAVASCRIPT node.js y npm === gran combinación cientos de plugins enorme flexibilidad

Slide 9

Slide 9 text

Manos a la obra

Slide 10

Slide 10 text

REQUISITOS node.js >= 0.8.0 y npm Gruntfile.js (.coffee) package.json npm install -g grunt-cli

Slide 11

Slide 11 text

PACKAGE.JSON { "name": “bbalm-project", "version": "0.1.0", "devDependencies": { "grunt": "~0.4.2", "grunt-contrib-uglify": “~0.2.2”, // Todos los demás plugins } } npm install +

Slide 12

Slide 12 text

npm init npm install grunt --save-dev PACKAGE.JSON npm install --save-dev

Slide 13

Slide 13 text

GRUNTFILE.JS module.exports = function(grunt) { grunt.initConfig({ pkg: grunt.file.readJSON('package.json'), uglify: { options: { banner: '/*! <%= pkg.name %> */\n' }, build: { src: 'src/<%= pkg.name %>.js', dest: 'build/<%= pkg.name %>.min.js' } } }); ! grunt.loadNpmTasks('grunt-contrib-uglify'); grunt.registerTask('default', ['uglify']); }; función principal configuración carga módulos declara tareas

Slide 14

Slide 14 text

module.exports = function(grunt) { grunt.initConfig({ uglify: { build: { src: 'src/bbalm.js', dest: 'build/bbalm.min.js' } }, concat: { dist: { src: ['src/a.js', 'src/b.js'], dest: 'src/bbalm.js' } } }); ! grunt.loadNpmTasks(‘grunt-contrib-uglify'); grunt.loadNpmTasks(‘grunt-contrib-concat’); ! grunt.registerTask('default', [‘uglify']); grunt.registerTask(‘prod’, [‘concat’, ‘uglify:build’]); };

Slide 15

Slide 15 text

grunt-contrib-clean grunt-contrib-coffee PLUGINS MANTENIDOS POR GRUNT grunt-contrib-compass grunt-contrib-compress grunt-contrib-concat grunt-contrib-connect grunt-contrib-copy grunt-contrib-cssmin grunt-contrib-htmlmin grunt-contrib-imgmin grunt-contrib-jasmine grunt-contrib-jshint grunt-contrib-less grunt-contrib-sass grunt-contrib-watch

Slide 16

Slide 16 text

GRUNT LESS grunt.initConfig({ less: { dev: { options: {sourceMap: true}, files: { “style/bbalm.css": “src/style/bbalm.less” } }, prod: { options: {cleancss: true}, files: { “style/bbalm.min.css”: “src/style/bbalm.less” } } } }); grunt less / grunt less:dev / grunt less:prod

Slide 17

Slide 17 text

GRUNT WATCH grunt.initConfig({ watch: { css: { files: [‘src/style/*.less’], tasks: [‘less:dev’], options: { livereload: 1337, }, }, coffee: { files: [‘src/scripts/*.coffee'], tasks: [‘coffee:src’, ‘coffee:test’, ‘test’], } } }); grunt watch / grunt watch:css / grunt watch:coffee

Slide 18

Slide 18 text

GRUNT CONNECT grunt.initConfig({ connect: { server: { options: { port: 9001, hostname: ‘localhost’, base: ‘dist’, open: true, livereload: 1337 // true } } } }); grunt connect / grunt connect:server

Slide 19

Slide 19 text

TODO JUNTO grunt.loadNpmTasks(‘grunt-contrib-connect'); grunt.loadNpmTasks(‘grunt-contrib-watch'); grunt.loadNpmTasks(‘grunt-contrib-less'); grunt.loadNpmTasks(‘grunt-contrib-coffee'); ! grunt.registerTask('default', [‘connect’, ‘watch’]);

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 text

SOURCE MAPS //@ sourceMappingURL=/path/to/file.js.map X-SourceMap: /path/to/file.js.map

Slide 22

Slide 22 text

MUCHA MÁS AUTOMATIZACIÓN

Slide 23

Slide 23 text

MUCHA MÁS AUTOMATIZACIÓN crea la estructura básica de tu proyecto y toda la configuración para empezar viene con toda la configuración y tareas para que montes, pruebes y previsualices manejo de dependencias para el navegador para que no tengas que hacerlo a mano

Slide 24

Slide 24 text

REQUISITOS node.js >= 0.8.0 y npm npm install -g yo npm install -g grunt-cli bower npm install -g

Slide 25

Slide 25 text

APP DE EJEMPLO $ npm install -g generator-webapp $ yo webapp bbalmapp ! $ cd bbalmapp $ bower install underscore ! # lanza la app en un servidor con livereload $ grunt server ! # prepara la aplicación para producción $ grunt

Slide 26

Slide 26 text

YO ANGULAR $ npm install -g generator-angular $ yo angular ! $ bower install angular-ui ! # corre los test unitarios de la app $ grunt test ! # lanza la app en un servidor con livereload $ grunt server ! # prepara la aplicación para producción $ grunt

Slide 27

Slide 27 text

AÚN HAY MÁS $ yo angular:controller miControlador $ yo angular:directive miDirectiva $ yo angular:filter miFiltro $ yo angular:service miServicio

Slide 28

Slide 28 text

“Deja a Grunt hacer todo el trabajo y céntrate en lo importante!” Dirk Ginader

Slide 29

Slide 29 text

No content

Slide 30

Slide 30 text

¡Gracias! ¿Preguntas? =)

Slide 31

Slide 31 text

KUDOS grunt.js: http://gruntjs.com/ grunt connect: https://npmjs.org/package/grunt-contrib-connect grunt watch: https://npmjs.org/package/grunt-contrib-watch yeoman: http://yeoman.io/ bower: http://bower.io/ yo angular: https://github.com/yeoman/generator-angular yo webapp: https://github.com/yeoman/generator-webapp