Gruntfile starter and package.json to match
{
"name": "site name",
"version": "0.0.0",
"description": "site name",
"main": "index.html",
"scripts": {
"test": "none"
},
"repository": {
"type": "git",
"url": "none"
},
"keywords": [
"none"
],
"engines": {
"node": ">=0.10.0"
},
"author": "Chris Whitney",
"license": "none",
"devDependencies": {
"grunt-contrib-jshint": "0.8.0",
"jshint": "2.4.3",
"jshint-stylish": "0.1.5",
"time-grunt": "0.2.10",
"grunt-contrib-watch": "0.5.3",
"grunt-contrib-connect": "0.7.1"
},
"dependencies": {
"grunt": "0.4.2",
"matchdep": "0.3.0",
"grunt-contrib-concat": "0.3.0",
"grunt-contrib-imagemin": "0.4.1",
"grunt-contrib-uglify": "0.4.0",
"grunt-contrib-requirejs": "0.4.3",
"grunt-contrib-sass": "0.7.2"
}
}/* global module: false */
/* build watch sass and js */
/**
* Grunt Module
*/
module.exports = function(grunt) {
'use strict';
var target = grunt.option("ENV") || 'dev',
environment = 'dist';
if (target === 'dev') {
require('time-grunt')(grunt);
environment = 'dev';
}
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
project: {
app: 'app',
assets: '<%= project.app %>/assets',
css: '<%= project.assets %>/css',
img: '<%= project.assets %>/img',
js: '<%= project.assets %>/js',
scss: '<%= project.assets %>/src/scss',
src_img: '<%= project.assets %>/src/img',
src_js: '<%= project.assets %>/src/js',
},
connect: {
server: {
options: {
port: 8880,
hostname: "0.0.0.0",
base: '<%= project.app %>',
keepalive: true,
},
},
},
imagemin: {
dynamic: {
files: [{
expand: true,
cwd: '<%= project.src_img %>',
src: ['**/*.{png,jpg,gif}'],
dest: '<%= project.img %>'
}],
},
},
sass: {
dev: {
files: {
'<%= project.css %>/style.css': '<%= project.scss %>/style.scss',
},
options: {
style: 'nested',
quiet: true,
sourcemap: true,
},
},
dist: {
options: {
style: 'compressed',
compass: false,
},
files: {
'<%= project.css %>/style.css': '<%= project.scss %>/style.scss',
},
},
},
jshint: {
all: '<%= project.src_js %>/{,*/}*.js',
options: {
ignores: ['<%= project.src_js %>/lib/handlebars.js'],
jshintrc: '.jshintrc',
force: function () {
// adding --force to the grunt commmand breaks sass
return (target === 'dev');
},
reporter: require('jshint-stylish'),
},
},
uglify: {
modernizr: {
options: {
optimize: "uglify2",
},
files: {
'<%= project.js %>/respond.js': '<%= project.src_js %>/lib/respond/respond.js',
'<%= project.js %>/modernizr.js': '<%= project.src_js %>/lib/modernizr/modernizr.js',
'<%= project.js %>/require.js': '<%= project.src_js %>/lib/requirejs/require.js',
}
}
},
requirejs: {
dev: {
options: {
baseUrl: '<%= project.src_js %>',
mainConfigFile: '<%= project.src_js %>/main.js',
include: "main",
preserveLicenseComments: false,
optimize: "none",
generateSourceMaps: true,
out: '<%= project.js %>/main.js',
logLevel: 2,
},
},
dist: {
options: {
baseUrl: '<%= project.src_js %>',
mainConfigFile: '<%= project.src_js %>/main.js',
include: "main",
preserveLicenseComments: true,
optimize: "uglify2",
generateSourceMaps: false,
out: '<%= project.js %>/main.js',
},
},
},
watch: {
sass: {
files: '<%= project.scss %>/{,*/}*.scss',
tasks: ['sass:dev'],
},
require: {
files: ['<%= project.src_js %>/{,*/}*.js'],
tasks: ['jshint', 'requirejs:dev'],
},
imagemin: {
files: ['<%= project.src_img %>/{,*/}*'],
tasks: ['imagemin'],
},
livereload: {
// get live reload at
// https://chrome.google.com/webstore/detail/livereload/jnihajbhpnppcggbcgedagnkighmdlei
options: {
livereload: true,
},
files: [
'<%= project.css %>/*.css',
'<%= project.img %>/*',
'<%= project.js %>/*.js',
'<%= project.app %>/*.html',
],
},
grunt: {
files: ['Gruntfile.js', 'package.json'],
},
},
});
var build_type = ['sass:dev', 'imagemin', 'jshint', 'requirejs:dev', 'uglify'];
if (target !== 'dev') {
require('matchdep').filter('grunt-*').forEach(grunt.loadNpmTasks);
build_type = ['sass:dist', ':dist'];
grunt.registerTask('build-js', ['requirejs:dist']);
} else {
require('matchdep').filterAll('grunt-*').forEach(grunt.loadNpmTasks);
grunt.registerTask('build-js', ['jshint', 'requirejs:dev']);
}
grunt.registerTask('build-css', ['sass:' + environment]);
grunt.registerTask('build', build_type);
};