Intro to grunt

41
Intro to Grunt 1
  • Upload

    -
  • Category

    Internet

  • view

    51
  • download

    0

Transcript of Intro to grunt

Page 1: Intro to grunt

Intro to Grunt

1

Page 2: Intro to grunt

2

A JavaScript Tasks Runner

Uglify JS/CSS

Compile Jade/SASS/Coffeescript

HTML hint

A lot more to explore…

CSS sprite

Intro to Grunt

Page 3: Intro to grunt

Install

$ sudo npm install -g grunt-cli

(1)Based on NodeJS

$ grunt - - version

3

“cli” stands for “Command Line Interface”

Page 4: Intro to grunt

(2)Depended on 2 Files

1. package.json

$ npm install

4

Page 5: Intro to grunt

2. gruntfile.js

(2)Depend on 2 Files

5

Page 6: Intro to grunt

Thanks!

That’s all!

6

Page 7: Intro to grunt

Demo

7

practice makes perfect!

Page 8: Intro to grunt

Demo 1: Uglify JS

package.json

$ npm install

OR

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

8

Page 9: Intro to grunt

gruntfile.js

dest src(array)

Demo 1: Uglify JS

9

:

Page 10: Intro to grunt

OR

$ grunt uglify

gruntfile.js

$ grunt default

Demo 1: Uglify JS

10

$ grunt

Page 11: Intro to grunt

11

WTF?!

http://gruntjs.com

Page 12: Intro to grunt

Use ‘Watch’!!!

12

Page 13: Intro to grunt

Demo 2: Adding watch

package.json

$ npm install

OR

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

13

Page 14: Intro to grunt

gruntfile.js

Srctasks

$ grunt watch

Demo 2: Adding watch

Let’s watch it!

14

Page 15: Intro to grunt

Use matchdep!!!

15

Page 16: Intro to grunt

Demo 3: add matchdep

package.json

$ npm install

OR

$ npm install matchdep - -save-dev

16

Page 17: Intro to grunt

gruntfile.js

Demo 3: add matchdep

17

Page 18: Intro to grunt

Demo 3: add matchdep

18

load-grunt-tasks

Page 19: Intro to grunt

Demo 3: compile coffee

package.json

$ npm install

OR

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

19

Page 20: Intro to grunt

Demo 3: compile coffee

gruntfile.js

dest: src

Srctasks

Let’s watch it!

20

Page 21: Intro to grunt

$ grunt watch

21

Page 22: Intro to grunt

CoffeeScript

JavaScript

uglified JS

in one step!

22

Page 23: Intro to grunt

Demo 4: compile coffee to uglified

gruntfile.js

Custom task name hereLet’s watch it!

$ grunt watch

23

Page 24: Intro to grunt

main.js

24

Demo 4: compile coffee to uglified

Page 25: Intro to grunt

Demo 5: compile sass

package.json

$ npm install

OR

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

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

25

Page 26: Intro to grunt

gruntfile.js

dest: src

Demo 5: compile sass

26

Page 27: Intro to grunt

$ grunt watch

Demo 5: compile sass

Let’s watch it!

27

is also called “multi tasks”

Page 28: Intro to grunt

Demo 5: compile sass

28

Page 29: Intro to grunt

29

Page 30: Intro to grunt

Configuring Tasks: tasks

$ grunt uglify

$ grunt coffee

Tasks

30

Page 31: Intro to grunt

Configuring Tasks: targets

targets

tasks

$ grunt sass:dist

$ grunt sass:build

$ grunt sass

31

Page 32: Intro to grunt

Configuring Tasks: options

options

tasks

32

Page 33: Intro to grunt

Configuring Tasks: files

Compact Format

33

Page 34: Intro to grunt

files object Format

Configuring Tasks: files

34

Page 35: Intro to grunt

files array Format

Configuring Tasks: files

35

Page 36: Intro to grunt

Configuring Tasks:

36

custom filter function

fs.Stats method name

Page 37: Intro to grunt

Configuring Tasks: templates

37

Page 38: Intro to grunt

38

practice makes perfect!

Demo

Page 39: Intro to grunt

gruntfile.js

Templates Demo: Uglify JS

39

Page 40: Intro to grunt

http://gruntjs.com/plugins

http://gruntjs.com/

Resources

40

http://compass-style.org

http://coffeescript.org

http://jade-lang.com

http://sass-lang.com

http://gulpjs.com/

Page 41: Intro to grunt

Thanks Again!

41