23
wherethetruck.at @JackBarker GETTING STARTED WITH #WPMelb

Grunt js and WordPress

Embed Size (px)

DESCRIPTION

Working with Grunt JS and WordPress. A presentation by Jack Barker at the WordPress Melbourne Meetup April 2014

Citation preview

Page 1: Grunt js and WordPress

wherethetruck.at @JackBarker

GETTING STARTED WITH

#WPMelb

Page 2: Grunt js and WordPress

WHAT IS GRUNT ???

• “The JavaScript task runner”

• gruntjs.com

• Cross-platform

• Runs on Node.js

• nodejs.org

Page 3: Grunt js and WordPress
Page 4: Grunt js and WordPress

SO… WHAT EXACTLY ARE YOU AUTOMATING?

Page 5: Grunt js and WordPress

WHY AUTOMATE WITH GRUNT?

Page 6: Grunt js and WordPress

Functionality

Ease of use

Page 7: Grunt js and WordPress
Page 8: Grunt js and WordPress

1. INSTALL GRUNT CLIsudo npm install -g grunt-cli

Node Package Manager

GlobalGrunt: Command Line Interface

Install

Super User: Do

Page 9: Grunt js and WordPress

If it doesn’t say “Error”, then it

worked!

Page 10: Grunt js and WordPress

2. DECIDE WHERE TO CREATE PROJECT

Project Root

Wordpress / public_html

wp_content

wp_config.php

[…etc]

package.json

Page 11: Grunt js and WordPress

3. CREATE NODE PROJECTcd [your project root]

npm init

npm install grunt --save-dev• Change directory;

• Node Package Manager;Initialise a new project

• Node Package Manager;Install grunt to our project; andAdd it to our list of project dependencies

Page 12: Grunt js and WordPress

WHAT DID THAT DO?

Page 13: Grunt js and WordPress

4. GRUNT PLUGINS

• Javascript minification: grunt-contrib-uglify

• File concatenation: grunt-contrib-concat

• Unit Testing: grunt-contrib-qunit

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

• JS hint: grunt-contrib-jshint

• Watch: grunt-contrib-watch

• GitHub

• Wordpress Deployment grunt-wordpress-deployhttps://www.npmjs.org/package/grunt-wordpress-deploy

Page 14: Grunt js and WordPress
Page 15: Grunt js and WordPress

5. WRITE OUR GRUNTFILEProject Root

wordpress

wp_content

wp_config.php

[…etc]

Gruntfile.js

node_modules

package.json

Page 16: Grunt js and WordPress

WORKED EXAMPLE (UGLIFY)

Page 17: Grunt js and WordPress
Page 18: Grunt js and WordPress

Example: https://github.com/gruntjs/grunt-contrib-uglify

Applied to Wordpress

Page 19: Grunt js and WordPress

RESULT

Page 20: Grunt js and WordPress

WORKED EXAMPLE (IMAGEMIN)

npm install grunt-contrib-imagemin --save-dev

Page 21: Grunt js and WordPress
Page 22: Grunt js and WordPress
Page 23: Grunt js and WordPress

MORE INFORMATION

• Grunt.js http://gruntjs.com/getting-started

• Chris Coyier :http://24ways.org/2013/grunt-is-not-weird-and-hard/

• Smashing Magazine:http://www.smashingmagazine.com/2013/10/29/get-up-running-grunt/

• Github