grunt-presentation



grunt-presentation

0 0


grunt-presentation

Grunt.js presentation made with Reveal.js and Yeoman

On Github FilipStenbeck / grunt-presentation

Build tool for the frontend slacker

AUTOMATION

FOR INSTANCE

  • Compilation (CoffeeScript, Closure, Sass, Less)
  • Concatenating
  • Minification (JS, HTML, CSS)
  • Copying
  • Testing
  • JavaScript 'Linting'
  • Live Reload

Why Grunt?

  • JavaScript
  • Open source
  • Community
  • Hundreds of plugins...
  • ... and it is possible to write your own
  • Easy

Easy to install

npmjs.org -- 2013-08-11
npm install -g grunt-cli
            package.json
{
  "name": "grunt-demo",
  "version": "0.1.0",
  "description": "Small demo of grunt",
  "author": "Filip Stenbeck",
  "license": "BSD",
  "devDependencies": {
    "grunt": "~0.4.1",
    "grunt-contrib-copy": "~0.4.0",
    "grunt-contrib-concat": "~0.1.3",
    "grunt-contrib-uglify": "~0.2.0",
    "grunt-contrib-jshint": "~0.3.0",
    "grunt-contrib-watch": "~0.4.3",
    "grunt-contrib-clean": "~0.4.1",
    "grunt-contrib-htmlmin": "~0.1.1",
    "grunt-usemin": "~0.1.12"
  }
}
npm install
npm install grunt-contrib-coffee --save-dev

Easy to configure

        module.exports = function(grunt) {
                 grunt.initConfig({
                     ...
                     ..
                     .
                 }
             };
    
        jshint: {
            options: {
                jshintrc: '.jshintrc',
            },
            all: ['Gruntfile.js','script/*.js']
        }
    
        concat: {
            dist: {
                src: ['script/*.js'],
                dest: 'dist/js/app.js'
            }
        }
    
        uglify: {
            dist: {
                files: {
                    'dist/js/app-min.js': ['dist/js/app.js' ]
                }
            }
        }
    
        
            grunt.loadNpmTasks('grunt-contrib-concat');
            grunt.loadNpmTasks('grunt-contrib-uglify');
            grunt.loadNpmTasks('grunt-contrib-jshint');

            grunt.registerTask('build', ['jshint',concat','uglify']);
        
    

Easy to run

grunt [taskname]

DEMO

Easy to delete

Tips 'n Tricks

Use variables in Gruntfile.js

        
        module.exports = function (grunt) {
              var globalConfig = {
                src: 'src',
                dest: 'dist'
              };
          ...
          ..
          .
        
    
        

          jshint: {
              all: [
                  'Gruntfile.js', '<%= globalConfig.src %>/js/{,*/}*.js'
              ]
          },
        
    

'matchdep' to load plugins

        
    npm install --save-dev matchdep
        
    
        
  require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);
        
    

Alias

        
    grunt.registerTask('build', [
    'clean:dist',
    'useminPrepare',
    'concat',
    'copy',
    'cssmin',
    'uglify',
    'usemin'
  ]);

  grunt.registerTask('build-with-style', [
    'jshint',
    'build'
  ]);
        
    

Use watch

        watch: {
            coffee: {
                files: ['coffee/*.coffee'],
                tasks: ['compile','jshint'],
                options: {
                    spawn: false
                }
            },
            javascript: {
                files: ['js/*.js'],
                tasks: ['jshint'],
                options: {
                    spawn: false
                }
            }
        },
    

Yeoman

Credits