Last active
December 23, 2015 10:08
-
-
Save miguelmota/6618901 to your computer and use it in GitHub Desktop.
A simple gruntfile boilerplate that I use for single page web apps.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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']); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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