Skip to content

Instantly share code, notes, and snippets.

@rnarian
Created February 24, 2014 10:06
Show Gist options
  • Save rnarian/9184961 to your computer and use it in GitHub Desktop.
Save rnarian/9184961 to your computer and use it in GitHub Desktop.
Gruntconfig + package.json
module.exports = function(grunt) {
require('load-grunt-tasks')(grunt);
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
dirs: {
bower: 'bower_components',
css: 'assets/css',
js: 'assets/js',
images: 'assets/images',
icons: 'assets/icons'
},
// SCSS
sass: {
dev: {
options: {
style: 'expanded'
},
files: {
'<%= dirs.css %>/style.css': '<%= dirs.css %>/scss/style.scss'
}
},
build: {
options: {
style: 'compressed'
},
files: {
'<%= dirs.css %>/style.css': '<%= dirs.css %>/scss/style.scss'
}
}
},
// CSS autoprefixer
autoprefixer: {
options: {
browsers: ['last 2 versions']
},
dist: {
files: {
'<%= dirs.css %>/style.css': '<%= dirs.css %>/style.css'
}
}
},
// Concat
concat: {
options: {
separator: ';',
},
dist: {
src: [
'<%= dirs.bower %>/jquery/dist/jquery.min.js',
'<%= dirs.bower %>/jquery-smartresize/jquery.smartresize.js',
'<%= dirs.js %>/*.js',
'!<%= dirs.js %>/build.js'
],
dest: '<%= dirs.js %>/build.js',
},
},
// JShint
jshint: {
all: [
'Gruntfile.js',
'<%= dirs.js %>/*.js',
'!<%= dirs.js %>/build.js'
]
},
// Uglify
uglify: {
all: {
files: {
'<%= dirs.js %>/build.js': ['<%= dirs.js %>/build.js']
}
}
},
// Imagemin
imagemin: {
dynamic: {
files: [{
expand: true,
cwd: '<%= dirs.images %>',
src: ['**/*.{png,jpg,gif}'],
dest: '<%= dirs.images %>'
}]
}
},
// SVGmin
svgmin: {
options: {
plugins: [
{ removeViewBox: false },
{ removeUselessStrokeAndFill: false }
]
},
dist: {
files: [{
expand: true,
cwd: '<%= dirs.icons %>',
src: ['*.svg'],
dest: '<%= dirs.icons %>/_min',
ext: '.svg'
}]
}
},
// Grunticon
grunticon: {
icons: {
files: [{
expand: true,
cwd: '<%= dirs.icons %>/_min',
src: ['*.svg', '*.png'],
dest: "<%= dirs.icons %>/grunticon"
}],
options: {
cssprefix: ".icon--",
customselectors: {
"*": [".btn--$1:before", ".icon--$1:before", ".logo--$1"]
}
}
}
},
// HTMLHint
htmlhint: {
html: {
src: ['<%= dirs.templates %>/*.html5']
}
},
// Browser Sync
browser_sync: {
dev: {
bsFiles: {
src : 'assets/css/style.css'
},
options: {
watchTask: true,
server: {
baseDir: ""
},
ghostMode: {
clicks: true,
scroll: true,
links: true,
forms: true
},
}
}
},
// Watch
watch: {
options: {
livereload: true
},
sass: {
files: ['<%= dirs.css %>/**/*.scss'],
tasks: ['sass:dev', 'autoprefixer']
},
images: {
files: ['<%= dirs.images %>/*.{png,jpg,gif}'],
tasks: ['imagemin']
},
icons: {
files: ['<%= dirs.icons %>/*'],
tasks: ['svgmin', 'grunticon']
},
tpl: {
files: ['<%= dirs.templates %>/*'],
tasks: ['htmlhint']
},
scripts: {
files: ['Gruntfile.js', '<%= dirs.js %>/*.js'],
tasks: ['jshint', 'concat'],
options: {
spawn: false
}
}
}
});
grunt.registerTask('default', ['sass:build', 'autoprefixer', 'concat', 'uglify', 'imagemin', 'svgmin', 'grunticon']);
grunt.registerTask('dev', ['watch']);
grunt.registerTask('dev:sync', ['browser_sync', 'watch']);
};
{
"name": "project-name",
"version": "0.1.0",
"devDependencies": {
"grunt": "~0.4.2",
"grunt-contrib-sass": "~0.7.2",
"load-grunt-tasks": "~0.3.0",
"grunt-autoprefixer": "~0.6.5",
"grunt-contrib-watch": "~0.5.3",
"grunt-contrib-jshint": "~0.8.0",
"grunt-contrib-concat": "~0.3.0",
"grunt-contrib-uglify": "~0.3.2",
"grunt-contrib-imagemin": "~0.4.1",
"grunt-svgmin": "~0.3.1",
"grunt-grunticon": "~1.0.0",
"grunt-browser-sync": "~0.5.7",
"grunt-htmlhint": "~0.4.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment