Skip to content

Instantly share code, notes, and snippets.

@guilbep
Created December 13, 2013 15:54
Show Gist options
  • Save guilbep/7946370 to your computer and use it in GitHub Desktop.
Save guilbep/7946370 to your computer and use it in GitHub Desktop.
best grunt file
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
copy: {
main: {
files: [{
expand: true,
cwd: './partials/',
src: ['**/*'],
dest: 'build/partials'
}, {
expand: true,
cwd: './',
src: ['index.html'],
dest: 'build/'
}, {
expand: true,
cwd: './vendor',
src: ['**/*js', '*/*js'],
dest: 'build/vendor'
}, {
expand: true,
cwd: './css/',
src: ['**/*'],
dest: 'build/css/'
}, {
expand: true,
cwd: './img/',
src: ['**/*'],
dest: 'build/img/'
}]
}
},
requirejs: {
compile: {
options: grunt.file.readJSON('build-config.json')
}
},
ngmin: {
files: {
src: 'build/js/main-src.js',
dest: 'build/js/main-src.js'
}
},
uglify: {
main: {
options: {
mangle: false,
report: 'min',
sourceMappingURL: './source-map.js',
sourceMap: 'build/js/source-map.js'
},
files: {
'build/js/main.js': ['build/js/main-src.js']
}
}
},
htmlmin: { // Task
dist: { // Target
options: { // Target options
removeComments: true,
collapseWhitespace: true
},
files: [{
expand: true,
cwd: './partials/',
src: ['**/*'],
dest: 'build/partials'
}, { // Dictionary of files
'build/index.html': 'index.html', // 'destination': 'source'
}]
}
},
watch: {
html: {
// files: ['*.html'],
files : ['**/*html', 'css/*css'],
options: {
// Start a live reload server on the default port 35729
livereload: true,
},
},
scripts: {
files: ['js/*.js', 'js/**/*.js'],
tasks: [],
options: {
interrupt: true
}
},
},
prettify: {
options: {
},
html: {
files: [ {'index.html' : 'index.html'},
{
expand: true,
cwd: './partials/',
src: ['**/*html'],
dest: 'partials'
}
]
}
},
"jsbeautifier" : {
"default": {
src : ["js/**/*.js"]
},
"git-pre-commit": {
src : ["js/**/*.js"],
options : {
mode:"VERIFY_ONLY"
}
}
}
});
// build build directory
grunt.loadNpmTasks('grunt-contrib-copy');
// minify js
grunt.loadNpmTasks('grunt-contrib-requirejs');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-ngmin')
// minify html
grunt.loadNpmTasks('grunt-contrib-htmlmin');
// watch constantly
grunt.loadNpmTasks('grunt-contrib-watch');
//beautify
grunt.loadNpmTasks('grunt-prettify');
grunt.loadNpmTasks('grunt-jsbeautifier');
grunt.registerTask('build-js', ['copy', 'requirejs', 'ngmin', 'uglify']);
grunt.registerTask('build-html', ['htmlmin']);
grunt.registerTask('build', ['build-js', 'build-html']);
grunt.registerTask('default', ['build']);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment