Automating your workflow with Grunt

Sponsored · Ship Features Fearlessly Turn features on and off without deploys. Used by thousands of Ruby developers. →

Automating your workflow with Grunt

Dimitris Tsironis

December 20, 2013

Annual Pro sale · Save $30

Have presentations of your own?

Share with private links, password protection, and more control over your work.

Transcript

33 slides
  1. About this This talk is about workflow patterns using Grunt

    reinvent your work, love JS more make your life easier
  2. Who Dimitris Tsironis Front-end Engineer at Splunk (ex-Bugsense) ! passionate

    about bringing BigData to the masses, eating bacon & geeing around
  3. Now

  4. Now

  5. Installation Edit your package.json file { "name": "my-project-name", "version": "0.1.0",

    "devDependencies": { "grunt": "~0.4.2", "grunt-contrib-jshint": "~0.6.3" } } grunt.loadNpmTasks(‘grunt-contrib-uglify'); Then in your Gruntfile.js add
  6. Gruntfile.js module.exports = function(grunt) { ! // Project configuration. grunt.initConfig({

    pkg: grunt.file.readJSON('package.json'), uglify: { options: { banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n' }, build: { src: 'src/<%= pkg.name %>.js', dest: 'build/<%= pkg.name %>.min.js' } } }); ! // Load the plugin that provides the "uglify" task. grunt.loadNpmTasks('grunt-contrib-uglify'); ! // Default task(s). grunt.registerTask('default', ['uglify']); ! };
  7. Compiling LESS module: grunt-contrib-less less: { dashboard: { files: {

    "css/main.css": "less/style.less", "css/landing.css": "less/landing.less", } } }
  8. Running specs #1 module: grunt-contrib-jasmine jasmine: { src: [ 'specs/project.js'],

    options: { host: 'http://localhost:7000/', vendor: [ ‘libs/jquery.js’], helpers: [ 'specs/jasmine-jquery/lib/jasmine-jquery.js', ‘specs/bower_components/sinonjs/sinon.js' ], template: 'specs/index.tmpl', specs: 'specs/build/specs.js', keepRunner: true } },
  9. Running specs #2 module: grunt-contrib-connect connect: { server: { options:

    { port: 7000 } } } grunt.registerTask('specs', ['connect', 'jasmine']); Registering our custom “specs” tasks
  10. Watching files module: grunt-contrib-watch watch: { gruntfile: { files: '<%=

    jshint.gruntfile.src %>', tasks: ['jshint:gruntfile', 'concat', 'less'] }, less: { files: “less/**/*.less”, /* or use an array */ tasks: [‘less’, ‘concat’] }, specs: { files: “specs/**/*Specs.js” tasks: [‘specs’] } }
  11. Live reload module: grunt-reload reload: { port: 6001, proxy: {

    host: 'localhost' } }, watch: { less: { files: “less/**/*.less”, /* or use an array */ tasks: [‘less’, ‘concat’, ‘reload’] } }
  12. Usage $ bower install <package> Install the bower tool $

    bower install <package>#<version> or just install dependencies from bower.json $ bower install
  13. Defining a new package $ bower init { "name": "my-project",

    "version": "1.0.0", "main": "path/to/main.css", "ignore": [ ".jshintrc", "**/*.txt" ], "dependencies": { "<name>": "<version>" }, "devDependencies": { "<test-framework-name>": "<version>" } }
  14. Registering a package $ bower register <package-name> <git-endpoint> a valid

    manifest JSON Git tags (using semver) be available at a Git endpoint (e.g., GitHub); remember to push your Git tags!
  15. Bugsense.js plugin (see Gruntfile.js & bower.json) Addy Osmani presentation Grunt

    plugins Bower homepage (incl. Yeomann) Grunt homepage

More Decks by Dimitris Tsironis

Other Decks in Technology