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
Front-end development automation with Grunt
PDF
Grunt training deck
PDF
Grunt All Day
PDF
What makes me "Grunt"?
PDF
Automate All the Things with Grunt
PDF
Getting Started With Grunt for WordPress Development
PDF
Javascript is your (Auto)mate
PDF
Grunt & Front-end Workflow
PPTX
Modern Development Tools
PPTX
Introducing grunt, npm and sass
PDF
Quest for the Perfect Workflow for McrFRED
PDF
Automate your WordPress Workflow with Grunt.js
PDF
GruntJS
PDF
Grunt: the wild boar dev's best friend - WordCamp London 2018
PDF
Intro to grunt
PDF
Modern Web Application Development Workflow - EclipseCon France 2014
PPTX
Grunt Continuous Development of the Front End Tier
PDF
Get Grulping with JavaScript Task Runners (Matt Gifford)
PDF
Preprocessor Workflow with Grunt
Front-end development automation with Grunt
Grunt training deck
Grunt All Day
What makes me "Grunt"?
Automate All the Things with Grunt
Getting Started With Grunt for WordPress Development
Javascript is your (Auto)mate
Grunt & Front-end Workflow
Modern Development Tools
Introducing grunt, npm and sass
Quest for the Perfect Workflow for McrFRED
Automate your WordPress Workflow with Grunt.js
GruntJS
Grunt: the wild boar dev's best friend - WordCamp London 2018
Intro to grunt
Modern Web Application Development Workflow - EclipseCon France 2014
Grunt Continuous Development of the Front End Tier
Get Grulping with JavaScript Task Runners (Matt Gifford)
Preprocessor Workflow with Grunt

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)

DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
Big Data Technologies - Introduction.pptx
PDF
Encapsulation theory and applications.pdf
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Machine learning based COVID-19 study performance prediction
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
The AUB Centre for AI in Media Proposal.docx
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?
Per capita expenditure prediction using model stacking based on satellite ima...
Big Data Technologies - Introduction.pptx
Encapsulation theory and applications.pdf
“AI and Expert System Decision Support & Business Intelligence Systems”
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Machine learning based COVID-19 study performance prediction
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Spectral efficient network and resource selection model in 5G networks
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
NewMind AI Monthly Chronicles - July 2025
Mobile App Security Testing_ A Comprehensive Guide.pdf

Front End Development Automation with Grunt