Skip to content

Instantly share code, notes, and snippets.

@miguelmota
Last active December 23, 2015 10:08
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miguelmota/6618901 to your computer and use it in GitHub Desktop.
Save miguelmota/6618901 to your computer and use it in GitHub Desktop.
A simple gruntfile boilerplate that I use for single page web apps.
'use strict';
module.exports = function (grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
express: {
all: {
options: {
port: 9000,
hostname: 'localhost',
bases: './src',
livereload: true
}
}
},
jshint: {
files: ['src/js/main.js'],
options: {
globals: {
console: true,
module: true,
jQuery: true
}
}
},
concat: {
options: {
seperator: ';'
},
dist: {
src: [
'src/js/main.js'
],
dest: 'src/js/main.cat.js'
}
},
uglify: {
options: {
banner: '/*! <%= pkg.name %> <%= grunt.template.today("dd-mm-yyyy") %> */\n',
sourceMap: 'src/js/main.min.js.map',
sourceMapRoot: '/',
sourceMappingURL: 'src/js/main.min.js.map',
sourceMapPrefix: 1,
mangle: true,
compress: {
global_defs: {
'DEBUG': false
},
dead_code: true
},
report: 'min'
},
dist: {
files: {
'src/js/main.min.js': [
'src/js/main.js'
]
}
}
},
handlebars: {
options: {
namespace: 'App.Templates'
},
compile: {
files: {
'src/js/tmpls.js': [
'src/tmpls/index.hbs'
]
}
}
},
compass: {
dist: {
options: {
httpPath: '/',
sassDir: 'src/sass',
cssDir: 'dist/css',
relativeAssets: true,
outputStyle: 'compressed'
}
}
},
htmlmin: {
dist: {
options: {
removeComments: true,
collapseWhitespace: true,
removeRedundantAttributes: true,
collapseBooleanAttributes: true
},
files: {
'src/index.html': 'src/index.unmin.html'
}
}
},
watch: {
options: {
livereload: true
},
html: {
files: ['src/*.html'],
tasks: ['compile_html']
},
scripts: {
files: [
'src/js/main.js',
'src/tmpls/*.hbs',
tasks: ['compile_scripts']
},
css: {
files: ['src/sass/*.scss'],
tasks: ['compile_css']
}
},
shell: {
mycommand: {
command: 'echo "my command"',
options: {
stdout: true
}
}
}
});
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-handlebars');
grunt.loadNpmTasks('grunt-contrib-compass');
grunt.loadNpmTasks('grunt-contrib-htmlmin');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-express');
grunt.loadNpmTasks('grunt-shell');
grunt.registerTask('jshint', ['jshint']);
grunt.registerTask('compile_scripts', ['handlebars', 'uglify']);
grunt.registerTask('compile_css', ['compass']);
grunt.registerTask('compile_html', ['htmlmin']);
grunt.registerTask('default', ['express', 'watch']);
};
# Install dependencies
sudo npm install --save grunt grunt-cli grunt-contrib-jshint grunt-contrib-concat grunt-contrib-uglify grunt-contrib-handlebars grunt-contrib-compass grunt-contrib-htmlmin grunt-contrib-watch grunt-express grunt-shell
# Run
grunt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment