Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Grunt - An Introduction

Grunt - An Introduction

Short introduction to Grunt (What? Why? How?), Common use cases, What is Grunt not, Dependency management with Bower/npm

Momo Kornher

April 09, 2015
Tweet

More Decks by Momo Kornher

Other Decks in Programming

Transcript

  1. Why use a task runner? • Automation • Faster •

    Fail proof - or at least it will complain • Collaborative
  2. How to use Grunt Command line tool $ grunt Running

    "uglify:dist" (uglify) task File "dist/main.js" created. Uncompressed size: 389 bytes. Compressed size: 119 bytes gzipped (185 bytes minified). Done, without errors. $ grunt tests $ grunt phpunit:testSuiteOne
  3. How to use Grunt Gruntfile.js • Root directory • VCS/Git

    module.exports = function(grunt) { grunt.initConfig({ jshint: { files: ['Gruntfile.js', 'src/**/*.js', 'test/**/*.js'], options: { globals: { jQuery: true } } }, watch: { files: ['<%= jshint.files %>'], tasks: ['jshint'] } }); grunt.loadNpmTasks('grunt-contrib-jshint'); grunt.loadNpmTasks('grunt-contrib-watch'); grunt.registerTask('default', ['jshint']); };
  4. Interlude: npm & bower • Dependency management ◦ npm: for

    everything [node.js] ◦ bower: for everything web • Integrate well with Grunt
  5. Common use cases • CSS/JS pre processing • Minification •

    Image optimization • Testing / linting • File operations • HTML wiring
  6. Common use cases - even better! • CSS + images

    = spritemaps • (Simple) deployment • Grunt watch • Shell scripts • … and more!
  7. What Grunt NOT is • Limited to JavaScript (kind of)

    • Know your tools • No to non-interactive • Not an application