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

Giving your Development more Grunt - FOWA London 2013

Giving your Development more Grunt - FOWA London 2013

An in-depth introduction to GruntJS and some of the best plugins available.

Jack Franklin

October 25, 2013
Tweet

More Decks by Jack Franklin

Other Decks in Technology

Transcript

  1. npm

  2. module.exports = function(grunt) { grunt.initConfig({ // config goes here });

    grunt.loadNpmTasks(“grunt- contrib-uglify”); }; Gruntfile.js
  3. module.exports = function(grunt) { grunt.initConfig({ uglify: { minify: { files:

    { 'dist/out.js': ['src/*.js'] } } } }); ... }; Gruntfile.js
  4. uglify: { /* snip */ }, jshint: { all: ['Gruntfile.js',

    'src/ *.js'] }, // rest of Gruntfile Gruntfile.js
  5. > grunt jshint Running "jshint:all" (jshint) task >> 4 files

    lint free. Done, without errors. Running the task
  6. > grunt Running "jshint:all" (jshint) task >> 4 files lint

    free. Running "uglify:minify" (uglify) task File "dist/out.js" created. Done, without errors. Running grunt
  7. Running "jshint:all" (jshint) task Linting src/two.js ...ERROR [L2:C22] W033: Missing

    semicolon. console.log("file 2") Warning: Task "jshint:all" failed. Use --force to continue. Aborted due to warnings. Running grunt
  8. module.exports = function(grunt) { grunt.initConfig({ uglify: { minify: { files:

    { 'dist/out.js': ['src/*.js'] } } } }); ... }; Gruntfile.js
  9. uglify: { minify: { /* snip */ }, withBanner: {

    options: { banner: "/*Hello World*/" }, files: { 'dist/out.js': ['src/*.js'] } } }, // rest of Gruntfile Gruntfile.js
  10. uglify: { /*snip*/ }, watch: { files: [‘src/*.js’, ‘Gruntfile.js’], tasks:

    [‘jshint’], }, jshint: { /*snip*/ } Gruntfile.js
  11. > grunt watch Running "watch" task Waiting...OK >> File "src/two.js"

    changed. Running "jshint:all" (jshint) task >> 4 files lint free. Done, without errors. Completed in 0.470s at Wed Oct 23 2013 14:27:08 GMT+0100 (BST) - Waiting... Watching
  12. Gruntfile.js jshint: { /* snip */ }, jasmine: { test:

    { src: 'src/*.js', options: { specs: 'spec/*.js' } } }, watch: { /*snip */ },
  13. Testing > grunt jasmine Running "jasmine:test" (jasmine) task Testing jasmine

    specs via phantom . 1 spec in 0.001s. >> 0 failures Done, without errors.
  14. Default Task Running "jshint:all" (jshint) task >> 4 files lint

    free. Running "jasmine:test" (jasmine) task Testing jasmine specs via phantom . 1 spec in 0.002s. >> 0 failures Running "uglify:withBanner" (uglify) task File "dist/out.js" created. Done, without errors.
  15. Errors Running "jshint:all" (jshint) task >> 4 files lint free.

    Running "jasmine:test" (jasmine) task Testing jasmine specs via phantom x my app:: passes: failed Expected 2 to equal 3. (1) 1 spec in 0.002s. >> 1 failures
  16. Running "concurrent:target1" (concurrent) task Running "jshint:all" (jshint) task >> 4

    files lint free. Done, without errors. Running "jasmine:test" (jasmine) task Testing jasmine specs via phantom 1 spec in 0.001s. >> 0 failures Done, without errors. Running "uglify:withBanner" (uglify) task File "dist/out.js" created. Done, without errors.