Skip to content

Instantly share code, notes, and snippets.

@andrewfleming
Created July 13, 2017 03:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewfleming/166fe378542818201d45e0129f6cd944 to your computer and use it in GitHub Desktop.
Save andrewfleming/166fe378542818201d45e0129f6cd944 to your computer and use it in GitHub Desktop.
// See: http://24ways.org/2013/grunt-is-not-weird-and-hard/
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
clean: {
build: {
src: ['build/*']
}
},
copy: {
main: {
files: [
{
expand: true,
cwd: 'fonts/',
src: ['**'],
dest: 'build/fonts',
filter: 'isFile'
},
{
expand: true,
cwd: 'sass/vendor/',
src: ['**'],
dest: 'build/css/vendor/',
filter: 'isFile'
},
{
expand: true,
cwd: 'js/vendor/',
src: ['**'],
dest: 'build/js/vendor/',
filter: 'isFile'
},
],
},
},
csscomb: {
options: {
config: 'sass/csscomb.json'
},
build: {
expand: true,
cwd: 'sass/',
src: ['**/*.scss', '!_mixins.scss', '!_variables.scss'],
dest: 'sass/'
}
},
sass: {
options: {
compass: true,
style: 'expanded',
precision: 3,
require: [ 'sass-globbing', 'susy' ],
loadPath: [
'node_modules/node-normalize-scss/',
'bower_components/fontawesome/scss/',
'bower_components/breakpoint-sass/stylesheets/'
]
},
build: {
files: {
'build/css/style.css': 'sass/style.scss',
'build/css/editor-style.css': 'sass/editor-style.scss',
}
}
},
jshint: {
options: {
globals: {
jQuery: true
}
},
build: {
files: {
src: ['js/**/*.js', '!js/vendor/**/*.js']
}
}
},
concat: {
build: {
src: [
'js/biotext.js'
],
dest: 'build/js/scripts.js',
nonull: true
}
},
uglify: {
options: {
preserveComments: 'some',
},
build: {
files: {
'build/js/scripts.min.js': 'build/js/scripts.js',
'build/js/admin.min.js': 'build/js/admin.js'
}
}
},
postcss: {
options: {
map: true, // inline sourcemaps
processors: [
require('autoprefixer')({browsers: 'last 2 versions'}), // add vendor prefixes
]
},
dist: {
src: 'build/css/*.css'
}
},
csso: {
options: {
report: 'min'
},
build: {
files: [{
expand: true,
cwd: 'build/css/',
src: ['**/*.css', '!.min.css'],
dest: 'build/css/',
ext: '.min.css'
// 'build/css/style.min.css': ['build/css/style.css'],
// 'build/css/editor-style.min.css': ['build/css/editor-style.css']
}]
}
},
imagemin: {
options: {
cache: false // Bug: https://github.com/gruntjs/grunt-contrib-imagemin/issues/140
},
build: {
files: [{
expand: true,
cwd: 'images/',
src: ['**/*.{png,jpg,gif,svg}'],
dest: 'build/images/'
}]
}
},
watch: {
options: {
livereload: true
},
js: {
files: ['js/**/*.js'],
tasks: ['concat'],
options: {
spawn: false,
livereload: true,
}
},
css: {
files: ['sass/**/*.scss'],
tasks: ['sass', 'postcss' ],
options: {
livereload: true,
spawn: false
}
},
images: {
files: ['images/**/*'],
tasks: ['newer:imagemin'],
options: {
spawn: false
}
},
},
criticalcss: {
frontpage: {
options: {
url: "http://local.biotext.com.au",
width: 1200,
height: 900,
outputfile: "./build/css/critical/frontpage.css",
filename: "./build/css/style.css", // Using path.resolve( path.join( ... ) ) is a good idea here
buffer: 800*1024,
ignoreConsole: true
}
}
},
});
grunt.loadNpmTasks('grunt-postcss');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-imagemin');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-sass');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-csscomb');
grunt.loadNpmTasks('grunt-csso');
grunt.loadNpmTasks('grunt-newer');
// grunt.loadNpmTasks('grunt-notify');
// grunt.loadNpmTasks('grunt-criticalcss');
// grunt.registerTask('default', ['clean', 'copy', 'sass', 'postcss', 'concat', 'imagemin', 'watch']);
grunt.registerTask('default', ['clean', 'copy', 'sass', 'postcss', 'concat', 'imagemin', 'csso', 'watch']);
grunt.registerTask('build', ['clean', 'copy', 'csscomb', 'sass', 'postcss', 'jshint', 'concat', 'uglify', 'imagemin', 'csso']);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment