SlideShare a Scribd company logo
Front-End Automation
with Grunt
Belén Albeza
@ladybenko
www.belenalbeza.com
A workflow example
Lint

Test
Open
browser

Watch
assets

Compile
assets
Run
server
Recompile
assets

Reload
browser
We do this already…
• python -m SimpleHTTPServer
• open index.html
• sass --watch sass:css
• jshint main.js
• ./conquer_the_world.sh

• Etc.
What if we integrate all
these tasks?
• We can setup long flows and run it with
just one task

• We can stop the flow if a task fails (for

instance, abort when linting spots an error)

• Everyone in the dev team can follow the
same workflow
Front End Development Automation with Grunt
Grunt
What is Grunt?
• A JavaScript task runner
npm install -g grunt-cli
• Lots of plugins for front-end and Node
development
Gruntfile.js
• A JavaScript file with our Grunt config
• Think of it as a Makefile, Rakefile, etc.
• We can use plugins that provide common
tasks…

• …or we can cook our own tasks!
module.exports(function (grunt) {
[‘a-cool-grunt-plugin’,
‘another-plugin’
].forEach(grunt.loadNpmTasks);
grunt.initConfig({
// ...
});
});
How to run tasks
•

grunt mytask will run all the targets of

•

grunt mytask:target will run the specific

mytask
target of mytask
grunt clean
grunt sass:dev
Linter
• A Linter analyses our code
• Looks for syntax errors (awesome for
script languages)

• Looks for formatting errors (ex: “don’t use
more than 80 chars per line!”)

• Looks for bad practises (ex: “you can’t use
this variable without declaring it first”)
Install JSHint plugin
• npm install grunt-contrib-jshint
• grunt jshint
grunt.initConfig({
jshint: {
all: [‘Gruntfile.js’,
‘js/**/*.js’]
}
});
Sass
• CSS, as a language, sucks
• Sass is a nice language that compiles to CSS
• We have variables, inheritance/mixins, a
clean syntax, partials...
@import _reset
$main-color: #cff
$fg-color: #000
@mixin std-button
background: $main-color
color: $fg-color
a.button, button
+std-button
Install Sass plugin
• npm install
• grunt sass

grunt-contrib-sass
grunt.initConfig({
sass: {
dev: {
options: {
style: ‘expanded’,
lineComments: true
},
files: {
‘css/main.css’: ‘sass/main.sass’
}
}
}
});
// 1-to-1 file mapping. Ex:
// sass/unicorn.sass -> css/unicorn.css
files: {
expand: true,
cwd: ‘sass’,
src: [‘**/*.sass’],
dest: ‘css’,
ext: ‘.css’
});
Watch
• You may have several daemons listening for
changes to files to do something

• Examples: Sass/LESS stylesheets,

CoffeeScript files, Handlebars templates,
etc.

• With Grunt you can group all of them in a
single place
Install Watch plugin
• npm install
• grunt watch

grunt-contrib-watch
grunt.initConfig({
watch: {
sass: {
files: [‘sass/**/*.sass’],
tasks: [‘sass:dev’]
}
}
});
Build your own flows
• You can create tasks than run other tasks
• Use them to set-up workflows, like “regular
development” or “build a release”.
grunt.registerTask(‘server’, [‘clean’,
‘jshint’, ‘sass:dev’, ‘jasmine’,
‘connect:server’, ‘open’, ‘watch’]);
grunt.registerTask(‘release’, [‘clean’,
‘jshint’, ‘sass:prod’, ‘jasmine’,
‘copy:release’]);
Create your own tasks
• If you don’t find the right plugin, you can
create your very own task…

• …and wrap it in a plugin so others can use
it as well ;)
grunt.registerTask(‘version’,
‘shows version number’, function () {
// implement our own task
var pkg = grunt.file.readJSON(
‘package.json’);
grunt.log.writeln(pkg.version);
});
Other useful plugins
• grunt-contrib-clean: deletes files and

directories (usefull for temporary files)

• grunt-contrib-jasmine: run Jasmine tests
from the console and in the browser

• grunt-contrib-copy: copy files (useful to
make builds)

• grunt-contrib-connect: run a local server
Browse more plugins
• http://gruntjs.com/plugins
• There are plugins to minify CSS, reload a
browser tab, create zips, erase files, build
assets (Handlebars, Coffee, LESS, etc.)…

OS grunt plugin!
• And our Firefoxgrunt-firefoxos:)
npm install
Sample code
https://github.com/
belen-albeza/grunt-demo
Demo
A different use case
• This is just not only for front-end or Node
development...

• Think of other projects you can automate!
A book!
A book in Leanpub
• Leanpub is a publishing platform
• You write your manuscripts in Markdown
(plain text) and put them into a shared
folder in Dropbox

• Then, they build a pretty eBook from your
plain text files
Problem
• You need to put your manuscript files in
Dropbox…

• …but I want my own version control in
Github…

• …and I have other files (PSD’s, sample

code, etc.) that I don’t want to put into that
folder
Grunt to the rescue
Lint sample
code
Convert
from Github
MD to
Leanpub MD

Zip sample
code
Copy MD
files to
Dropbox
More about Grunt
• Grunt’s official “Getting Started Guide”
www.gruntjs.com/getting-started

• How to create your own tasks http://
gruntjs.com/creating-tasks

• “Power-Up Your Front-End Development
with Grunt” www.leanpub.com/grunt
Thanks!
Questions?

@ladybenko

More Related Content

KEY
Introduction to NodeJS with LOLCats
PPTX
Create Rest API in Nodejs
PDF
Create a RESTful API with NodeJS, Express and MongoDB
PPTX
Ansible @ WebElement 2015
KEY
Server side scripting smack down - Node.js vs PHP
PDF
Automating WordPress Theme Development
PDF
문서화에 날개를 달아주는 Flybook CLI
PDF
Advanced front-end automation with npm scripts
Introduction to NodeJS with LOLCats
Create Rest API in Nodejs
Create a RESTful API with NodeJS, Express and MongoDB
Ansible @ WebElement 2015
Server side scripting smack down - Node.js vs PHP
Automating WordPress Theme Development
문서화에 날개를 달아주는 Flybook CLI
Advanced front-end automation with npm scripts

What's hot (20)

PPTX
Automating with Ansible
PDF
Cape Cod Web Technology Meetup - 2
PDF
Rackspace Hack Night - Vagrant & Packer
PPTX
Automating Your Daily Tasks with Scripting - RubyConf 2015 Taiwan
PPTX
Make JavaScript Lean, Mean, and Clean
PPTX
Build your own RasPiTV with Node.js & Socket.io
PDF
ClojureScript@node
ODP
node.js - Fast event based web application development
KEY
Performance and scalability with drupal
PDF
Angular2 ecosystem
KEY
Nodejs web,db,hosting
PPTX
Baking in the cloud with packer and puppet
PDF
Once upon a time, there were css, js and server-side rendering
ODP
CouchApp - Build scalable web applications and relax
PDF
Build App with Nodejs - YWC Workshop
PDF
Provisioning iOS CI Server with Ansible
PPTX
Packer, where DevOps begins
ODP
Lisp Meet Up #31, Clake: a GNU make-like build utility in Common Lisp
Automating with Ansible
Cape Cod Web Technology Meetup - 2
Rackspace Hack Night - Vagrant & Packer
Automating Your Daily Tasks with Scripting - RubyConf 2015 Taiwan
Make JavaScript Lean, Mean, and Clean
Build your own RasPiTV with Node.js & Socket.io
ClojureScript@node
node.js - Fast event based web application development
Performance and scalability with drupal
Angular2 ecosystem
Nodejs web,db,hosting
Baking in the cloud with packer and puppet
Once upon a time, there were css, js and server-side rendering
CouchApp - Build scalable web applications and relax
Build App with Nodejs - YWC Workshop
Provisioning iOS CI Server with Ansible
Packer, where DevOps begins
Lisp Meet Up #31, Clake: a GNU make-like build utility in Common Lisp
Ad

Viewers also liked (16)

PDF
27.1.2014, Tampere. Perinteinen mobiilimaailma murroksessa. Petri Niemi: Sing...
KEY
Single Page Applications - Desert Code Camp 2012
PDF
The rise of single-page applications
PPTX
Single page applications
PDF
An introduction in to the world of front end automation - frontend ne (02 07-15)
PDF
Js Automation. npm scripts & Gulp
PPTX
Making Single Page Applications (SPA) faster
PDF
The Dark Side of Single Page Applications
PDF
Single page applications
PPTX
Front-end development introduction (JavaScript). Part 2
PDF
Single page application
PDF
Single Page Applications
PDF
Measuring the Performance of Single Page Applications
PPTX
Building single page applications
PDF
Introduction To Single Page Application
PPTX
Single Page Application (SPA) using AngularJS
27.1.2014, Tampere. Perinteinen mobiilimaailma murroksessa. Petri Niemi: Sing...
Single Page Applications - Desert Code Camp 2012
The rise of single-page applications
Single page applications
An introduction in to the world of front end automation - frontend ne (02 07-15)
Js Automation. npm scripts & Gulp
Making Single Page Applications (SPA) faster
The Dark Side of Single Page Applications
Single page applications
Front-end development introduction (JavaScript). Part 2
Single page application
Single Page Applications
Measuring the Performance of Single Page Applications
Building single page applications
Introduction To Single Page Application
Single Page Application (SPA) using AngularJS
Ad

Similar to Front End Development Automation with Grunt (20)

PDF
Django dev-env-my-way
PPTX
Angular boilerplate generator
PDF
Continuous Integration with Open Source Tools - PHPUgFfm 2014-11-20
PDF
Front-end development automation with Grunt
PPTX
Modern web technologies
PDF
Building your own personal minion with grunt.js
PDF
Midwest php 2013 deploying php on paas- why & how
KEY
Depolying Drupal with Git, Drush Make and Capistrano
PDF
Lightning fast sass
PDF
What makes me "Grunt"?
PDF
Deploy like a pro!
PDF
I Just Want to Run My Code: Waypoint, Nomad, and Other Things
PPTX
WordPress automation and CI
PDF
LuisRodriguezLocalDevEnvironmentsDrupalOpenDays
PDF
Gulp and Compass
PPTX
CSS Regression Tests
PDF
Everything-as-code - A polyglot adventure
PDF
Everything-as-code. A polyglot adventure. #DevoxxPL
PPTX
Word press workflows and gulp
PDF
Leonid Vasilyev "Building, deploying and running production code at Dropbox"
Django dev-env-my-way
Angular boilerplate generator
Continuous Integration with Open Source Tools - PHPUgFfm 2014-11-20
Front-end development automation with Grunt
Modern web technologies
Building your own personal minion with grunt.js
Midwest php 2013 deploying php on paas- why & how
Depolying Drupal with Git, Drush Make and Capistrano
Lightning fast sass
What makes me "Grunt"?
Deploy like a pro!
I Just Want to Run My Code: Waypoint, Nomad, and Other Things
WordPress automation and CI
LuisRodriguezLocalDevEnvironmentsDrupalOpenDays
Gulp and Compass
CSS Regression Tests
Everything-as-code - A polyglot adventure
Everything-as-code. A polyglot adventure. #DevoxxPL
Word press workflows and gulp
Leonid Vasilyev "Building, deploying and running production code at Dropbox"

More from Ladies Who Code (6)

PDF
Mini Hacks: Big Difference (Sally Jenkinson)
PDF
Adventure Capitalism
PDF
LWC - Getting Big! Rebecca Garcia
PDF
Coders as Superheroes
PDF
Hackathons for Fun and Profit
PDF
Mobile & Me
Mini Hacks: Big Difference (Sally Jenkinson)
Adventure Capitalism
LWC - Getting Big! Rebecca Garcia
Coders as Superheroes
Hackathons for Fun and Profit
Mobile & Me

Recently uploaded (20)

PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Machine learning based COVID-19 study performance prediction
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Approach and Philosophy of On baking technology
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPT
Teaching material agriculture food technology
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
A Presentation on Artificial Intelligence
PPTX
Big Data Technologies - Introduction.pptx
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
KodekX | Application Modernization Development
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Unlocking AI with Model Context Protocol (MCP)
Machine learning based COVID-19 study performance prediction
20250228 LYD VKU AI Blended-Learning.pptx
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Approach and Philosophy of On baking technology
Chapter 3 Spatial Domain Image Processing.pdf
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Teaching material agriculture food technology
The AUB Centre for AI in Media Proposal.docx
NewMind AI Weekly Chronicles - August'25 Week I
A Presentation on Artificial Intelligence
Big Data Technologies - Introduction.pptx
“AI and Expert System Decision Support & Business Intelligence Systems”
Diabetes mellitus diagnosis method based random forest with bat algorithm
KodekX | Application Modernization Development
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Dropbox Q2 2025 Financial Results & Investor Presentation
CIFDAQ's Market Insight: SEC Turns Pro Crypto

Front End Development Automation with Grunt