40
WORKFLOW PARA DESENVOLVIMENTO MOBILE USANDO GRUNT.JS davidson fellipe front-end engineer na globo.com

Workflow para desenvolvimento mobile usando grunt.js

Embed Size (px)

DESCRIPTION

Workflow para desenvolvimento mobile usando grunt.js

Citation preview

Page 1: Workflow para desenvolvimento mobile usando grunt.js

WORKFLOW PARA

DESENVOLVIMENTO

MOBILE USANDO

GRUNT.JSdavidson fellipe

front-end engineer na globo.com

Page 2: Workflow para desenvolvimento mobile usando grunt.js

- HTML ~ 2001

- front-end engineer

- globo.com ~ 2010

- mais em fellipe.com

me

Page 3: Workflow para desenvolvimento mobile usando grunt.js

POR QUE

AUTOMATIZAMOS?

Page 4: Workflow para desenvolvimento mobile usando grunt.js

PREGUIÇOSOS

Page 5: Workflow para desenvolvimento mobile usando grunt.js

GRANDES

PROBLEMAS PARA

RESOLVER

Page 6: Workflow para desenvolvimento mobile usando grunt.js
Page 7: Workflow para desenvolvimento mobile usando grunt.js

TASK RUNNERS

Page 8: Workflow para desenvolvimento mobile usando grunt.js

GRUNT NÃO

É O ÚNICO

Page 9: Workflow para desenvolvimento mobile usando grunt.js

MAKE

ANT

RAKE

CAKE

GULP

SHELL

JAVA

RUBY

COFFEE

JS

Page 10: Workflow para desenvolvimento mobile usando grunt.js

ANT

MAKEFILE

<target name="js-compile-all" description="Compile JavaScript files with Closure" unless="skip-js-compile">

<echo>Compiling JS files in ${input.scripts.dir} in closure...</echo>

<apply executable="java" dest="${output.scripts.dir}">

<arg value="-jar"/>

<arg path="${jar.lib.dir}/closure-compiler.jar"/>

<arg line="--js"/>

<srcfile/>

<arg line="--js_output_file"/>

<targetfile/>

<fileset dir="${output.scripts.dir}" includes="**/*-main.debug.js" />

<mapper type="glob" from="*-main.debug.js" to="*-main.min.js"/>

</apply>

<echo>Finished compiling JS files</echo>

</target>xml

http://mechanics.flite.com/blog/2012/06/19/why-we-use-node-dot-js-and-grunt-to-build-javascript/

Page 11: Workflow para desenvolvimento mobile usando grunt.js

http://i1-news.softpedia-static.com/images/news2/Three-of-the-Windows-Users-Fears-and-Misconceptions-About-Linux-427770-2.jpg

Page 12: Workflow para desenvolvimento mobile usando grunt.js

VAMOS DE GRUNT?

Page 13: Workflow para desenvolvimento mobile usando grunt.js

<3

Page 14: Workflow para desenvolvimento mobile usando grunt.js

grunt.js

- fácil de usar

- grande número de plugins

- imensa comunidade open source

Page 15: Workflow para desenvolvimento mobile usando grunt.js

VIA LINHA DE COMANDO

USA NODE.JS

grunt.js

Page 16: Workflow para desenvolvimento mobile usando grunt.js

tasks

- testes

- pré-processadores

- js/css lint

- criar sprites

- concatenação

- otimização de imagens

Page 18: Workflow para desenvolvimento mobile usando grunt.js

200k

400k

600k

DOWNLOADS 2013/14

mayaprmarfebjandecnovaugjuljunmay

http://npm-stat.vorba.ch/charts.html?package=grunt

Page 19: Workflow para desenvolvimento mobile usando grunt.js

COMO

COMEÇAR ?

Page 20: Workflow para desenvolvimento mobile usando grunt.js

instalação

- instalar NODE + NPM

- $ npm install -g grunt-cli

Page 21: Workflow para desenvolvimento mobile usando grunt.js

configurar node?

Page 22: Workflow para desenvolvimento mobile usando grunt.js

$ make grunt-config

MAKEFILE

grunt-config:

@echo "✖ installing node..."; brew install node;

@echo '✖ installing npm...'; sudo curl https://npmjs.org/install.sh -k | sh;

@echo '✖ installing grunt...'; sudo npm install -g grunt-cli;

@sudo npm i --save-dev

make

Page 23: Workflow para desenvolvimento mobile usando grunt.js

package.json

{

"name": "poll",

"version": "0.0.1",

"devDependencies": {

"grunt": "~0.4.2",

"grunt-contrib-jshint": "~0.6.5",

"grunt-contrib-uglify": "~0.2.7",

"grunt-contrib-watch": "~0.5.3",

"load-grunt-tasks": "~0.2.0",

"grunt-contrib-compass": "~0.6.0",

"grunt-contrib-concat": "~0.3.0",

"grunt-contrib-clean": "~0.5.0",

"grunt-contrib-copy": "~0.4.1",

"grunt-shell": "~0.6.1"

}

}js

Page 24: Workflow para desenvolvimento mobile usando grunt.js

instalando definições

MAKEFILE

$ sudo npm i --save-dev

terminal

Page 25: Workflow para desenvolvimento mobile usando grunt.js

.gitignore

MAKEFILE

.DS_Store

...

node_modules

Page 26: Workflow para desenvolvimento mobile usando grunt.js

Gruntfile.json

module.exports = function(grunt) {

grunt.initConfig({

pkg: grunt.file.readJSON('package.json'), pathBase: 'poll/static/poll/',

pathSrc: '<%= pathBase %>src/',

pathBuild: '<%= pathBase %>build/',

compass: {},

shell: {}

});

grunt.loadNpmTasks(‘grunt-contrib-compass’);

grunt.loadNpmTasks(‘grunt-contrib-shell’);

grunt.loadNpmTasks(‘grunt-contrib-uglify’);

grunt.registerTask('build', ['compass:min',

'shell']);

};js

Page 27: Workflow para desenvolvimento mobile usando grunt.js

INSTALE O

LOAD-GRUNT-TASKS

$ npm install grunt-phonegap --save-dev

Page 28: Workflow para desenvolvimento mobile usando grunt.js

Gruntfile.json

module.exports = function(grunt) {

grunt.initConfig({

pkg: grunt.file.readJSON('package.json'), pathBase: 'static/poll/',

compass: {},

minify: {},

uglify: {},

shell: {}

});

// Load all tasks

require('load-grunt-tasks')(grunt);

grunt.registerTask('build', ['compass:min',

'uglify',

'shell']);

};js

Page 29: Workflow para desenvolvimento mobile usando grunt.js

-- save-dev

MAKEFILE

$ npm install nome-pacote --save-dev

terminal

Page 30: Workflow para desenvolvimento mobile usando grunt.js

task exemplogrunt-contrib-compass

widget.scss widget.css

Page 31: Workflow para desenvolvimento mobile usando grunt.js

grunt-contrib-compass

MAKEFILE

$ npm install grunt-contrib-compass --save-dev

terminal

Page 32: Workflow para desenvolvimento mobile usando grunt.js

package.json

MAKEFILE

{

"name": "projeto",

"version": "0.0.1",

"devDependencies": {

"grunt": "~0.4.2",

"load-grunt-tasks": "~0.2.0",

"grunt-contrib-compass": "~0.6.0"

}

}

js

Page 33: Workflow para desenvolvimento mobile usando grunt.js

taskcompass:dev

MAKEFILE

grunt.initConfig({

compass: {

dev: {

options: {

sassDir: 'src/scss',

cssDir: 'build/css',

imagesDir: 'src/img',

generatedImagesDir: 'build/img'

}

},

prod: { /* ... */ }

}});js

Page 34: Workflow para desenvolvimento mobile usando grunt.js

taskcompass:prod

MAKEFILE

grunt.initConfig({

compass: {

dev: { /* ... */ },

prod: {

options: {

sassDir: 'src/scss',

cssDir: 'build/css',

imagesDir: 'src/img',

generatedImagesDir: 'build/img',

outputStyle: 'compressed',

noLineComments: true

}}}});js

Page 35: Workflow para desenvolvimento mobile usando grunt.js

executando

$ grunt compass:dev

$ grunt compass:prod

Page 36: Workflow para desenvolvimento mobile usando grunt.js

grunt-contrib-watch

widget.scss widget.css

watch

Page 37: Workflow para desenvolvimento mobile usando grunt.js

taskwatch

MAKEFILE

grunt.initConfig({

watch: {

build: {

files: ['src/**/*.{scss, js}'],

tasks: [

'compass:dev', 'concat', 'uglify'

]

}

}

}); js

Page 38: Workflow para desenvolvimento mobile usando grunt.js

executando

$ grunt watch

Page 39: Workflow para desenvolvimento mobile usando grunt.js

grunt-phonegap

- npm install grunt-phonegap --save-dev

- wrapping para Phonegap 3.0 CLI

https://github.com/logankoester/grunt-phonegap

Page 40: Workflow para desenvolvimento mobile usando grunt.js

- fellipe.com/talks

- github.com/davidsonfellipe

- twitter.com/davidsonfellipe

obrigado