Skip to content

Instantly share code, notes, and snippets.

@cilice
Last active December 11, 2015 14:48
Show Gist options
  • Select an option

  • Save cilice/4616027 to your computer and use it in GitHub Desktop.

Select an option

Save cilice/4616027 to your computer and use it in GitHub Desktop.
module.exports = function (grunt) {
'use strict';
// Project configuration.
grunt.initConfig({
pkg: require('./package'),
meta: {
banner: '/*! <%= pkg.name %> - v<%= pkg.version %> - ' +
'<%= grunt.template.today("yyyy-mm-dd") %> */'
},
jshint: {
all: [
'Gruntfile.js',
'js/main.js'
],
options: {
jshintrc: '.jshintrc'
}
},
// Build modernizr
modernizr: {
devFile: 'js/vendor/modernizr-2.6.2.js',
outputFile : 'dist/js/vendor/modernizr-for-<%= pkg.version %>.min.js',
extra: {
shiv: true,
mq: true
},
// Minify
uglify: true,
// Files
files: ['js/**/*.js', 'scss/**/*.scss']
},
sass: {
dev: {
options: {
unixNewlines: true,
style: 'expanded'
},
files: {
'css/main.css': 'scss/main.scss'
}
},
deploy: {
options: {
style: 'compressed'
},
files: {
'dist/css/main-<%= pkg.version %>.min.css': 'scss/main.scss'
}
}
},
uglify: {
deploy: {
options: {
sourceMap: "dist/js/main-<%= pkg.version %>.min.map"
},
files: {
'dist/js/main-<%= pkg.version %>.min.js': [
'js/vendor/jquery-*.min.js',
'js/plugins/log.js',
'js/main.js'
],
}
}
},
watch: {
scss: {
files: ['scss/**/*.scss'],
tasks: 'sass:dev'
},
js: {
files: [
'Gruntfile.js',
'js/main.js'
],
tasks: 'jshint'
}
}
});
// Load some stuff
grunt.loadNpmTasks('grunt-modernizr');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-sass');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.registerTask( "fix-sourcemap", function() {
var paths = [],
fs = require("fs");
grunt.task.requires('uglify');
paths.push(grunt.config.get('uglify.deploy.options.sourceMap'));
for(var k in grunt.config.get('uglify.deploy.files')) {
paths.push(k);
}
paths.forEach(function( filename ) {
grunt.log.writeln(filename);
var text = fs.readFileSync( filename, "utf8" );
// Modify map/min so that it points to files in the same folder;
// see https://github.com/mishoo/UglifyJS2/issues/47
if ( /\.map$/.test( filename ) ) {
text = text.replace( /"(dist\/)?js\//g, "\"" );
fs.writeFileSync( filename, text, "utf-8" );
} else if ( /\.min\.js$/.test( filename ) ) {
text = text.replace( /sourceMappingURL="(dist\/)?js\//, "sourceMappingURL=" );
fs.writeFileSync( filename, text, "utf-8" );
}
});
});
// A task for development
grunt.registerTask('dev', ['jshint', 'sass:dev']);
// A task for deployment
grunt.registerTask('deploy', ['jshint', 'modernizr', 'sass:deploy', 'uglify', 'fix-sourcemap']);
// Default task
grunt.registerTask('default', ['jshint', 'sass:dev', 'uglify', 'fix-sourcemap']);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment