zanetaylor
1/20/2014 - 12:49 AM

Gruntfile boilerplate for a basic Foundation 5 prototype

Gruntfile boilerplate for a basic Foundation 5 prototype

'use strict';

module.exports = function(grunt) {
  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),

    // Compiles Sass to CSS and generates necessary files if requested
    compass: {
      options: {
        sassDir: 'app/assets/scss',
        cssDir: 'app/assets/css',
        //generatedImagesDir: '.tmp/images/generated',
        imagesDir: 'app/assets/img',
        javascriptsDir: 'app/assets/js',
        fontsDir: 'app/assets/fonts',
        importPath: 'app/bower_components/foundation/scss',
        httpImagesPath: '/assets/img',
        httpGeneratedImagesPath: '/assets/img/generated',
        httpFontsPath: '/assets/fonts',
        relativeAssets: false,
        assetCacheBuster: false,
        outputStyle: 'expanded'
      },
      server: {
        options: {
          debugInfo: true
        }
      },
      dist: {
        options: {
          outputStyle: 'compressed'
        }
      }
    },

    jshint: {
      options: {
        jshintrc: '.jshintrc'
      },
      all: [
        'Gruntfile.js',
        'app/assets/js/*.js'
      ]
    },

    clean: {
      dist: {
        src: ['dist/*']
      },
    },
    copy: {
      dist: {
        files: [{
          expand: true,
          cwd: 'app',
          src: [
            //'assets/css/**',
            'assets/js/polyfills/*.js',
            'assets/img/**',
            'assets/fonts/**',
            '**/*.html',
            '!**/*.scss',
            '!bower_components/**'
          ],
          dest: 'dist'
        }]
      },
    },

    useminPrepare: {
      html: 'app/index.html',
      options: {
        dest: 'dist'
      }
    },

    usemin: {
      html: ['dist/*.html'],
      css: ['dist/assets/css/*.css'],
      options: {
        assetsDirs: ['dist']
      }
    },

    watch: {
      grunt: {
        files: ['Gruntfile.js'],
        tasks: ['compass']
      },
      compass: {
        files: ['app/assets/scss/{,*/}*.{scss,sass}'],
        tasks: ['compass:server']
      },
      livereload: {
        files: ['app/*.html', 'app/assets/js/{,*/}*.js', 'app/assets/css/{,*/}*.css', 'app/assets/img/{,*/}*.{jpg,gif,svg,jpeg,png}'],
        options: {
          livereload: true
        }
      }
    },

    connect: {
      app: {
        options: {
          port: 9000,
          base: 'app/',
          livereload: true
        }
      },
      dist: {
        options: {
          port: 9001,
          base: 'dist/',
          keepalive: true,
          livereload: false
        }
      }
    }

  });

  grunt.loadNpmTasks('grunt-contrib-compass');
  grunt.loadNpmTasks('grunt-contrib-concat');
  grunt.loadNpmTasks('grunt-contrib-uglify');
  grunt.loadNpmTasks('grunt-contrib-cssmin');
  grunt.loadNpmTasks('grunt-contrib-watch');
  grunt.loadNpmTasks('grunt-contrib-clean');
  grunt.loadNpmTasks('grunt-contrib-copy');
  grunt.loadNpmTasks('grunt-contrib-jshint');
  grunt.loadNpmTasks('grunt-contrib-connect');
  grunt.loadNpmTasks('grunt-usemin');

  grunt.registerTask('build', ['compass:server']);
  grunt.registerTask('default', ['build', 'connect:app', 'watch']);
  grunt.registerTask('validate-js', ['jshint']);
  grunt.registerTask('server-dist', ['connect:dist']);
  grunt.registerTask('publish', ['clean:dist', 'compass:dist', 'validate-js', 'useminPrepare', 'copy:dist', 'concat', 'cssmin', 'uglify', 'usemin']);

};