Created
December 9, 2015 23:31
-
-
Save nyeholt/77cf92b6b0ad69742ce1 to your computer and use it in GitHub Desktop.
Grunt config
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
{ | |
"name": "default", | |
"version": "0.0.0", | |
"authors": [ | |
"Shea Dawson <shea@livesource.co.nz>" | |
], | |
"description": "IPF Theme", | |
"license": "MIT", | |
"private": true, | |
"ignore": [ | |
"**/.*", | |
"node_modules", | |
"bower_components", | |
"vendor", | |
"test", | |
"tests" | |
], | |
"dependencies": { | |
"jquery": "~2.1.3", | |
"html5-placeholder-polyfill": "~2.0.10" | |
} | |
} |
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
module.exports = function(grunt) { | |
// COMMANDS | |
// comple css and js - $ grunt | |
// optim - run $ grunt imgoptim | |
// FILE STRUCTURE | |
// css/app.css, css/app.min.css | |
// build/global/css/*.scss | |
// build/global/css/**/*.scss | |
// build/components/componentname/css/*.scss | |
// css/singlefile.css, css/singlefile.min.css | |
// build/global/solo/css/*.scss | |
// js/app.js, js/app.min.css | |
// build/global/js/*.js | |
// build/global/js/**/*.js | |
// build/components/componentname/js/*.js | |
// singlefile.js, singlefile.min.js | |
// build/global/solo/js/*.js | |
var watch = {}; | |
var uglify = {}; | |
var concat = {}; | |
var sass = {}; | |
var cssmin = {}; | |
// THEME =========================================/ | |
var themes = { | |
ipf: { | |
path: './', | |
theme: 'ipf', | |
skinfile: 'build/global/css/skin' | |
}, | |
ct: { | |
path: '../ipf-ct/', | |
theme: 'ipf-ct', | |
skinfile: '../ipf-ct/scss/skin' | |
} | |
} | |
var theme = grunt.option('theme'); | |
theme = typeof themes[theme] !== 'undefined' ? themes[theme] : themes.ipf; | |
console.log('Running grunt for theme ' + theme.theme); | |
grunt.registerTask('skin', function () { | |
grunt.file.write('build/global/css/skinport.scss', '@import "' + theme.skinfile + '";'); | |
}); | |
// WATCH =========================================/ | |
watch.solocss = { | |
files: 'build/solo/css/*.scss', | |
tasks: [ | |
'newer:sass:solo' | |
] | |
}; | |
watch.appcss = { | |
files: [ | |
'build/global/css/*.scss', | |
'build/components/**/*.scss', | |
theme.skinfile + '.scss' | |
], | |
tasks: [ | |
'sass:app', | |
'concat:appcss', | |
'sass:solo' // run solo here too incase there are changes to sass vars etc | |
] | |
}; | |
watch.cssmin = { | |
files: [ | |
theme.path + 'css/*.css', | |
'!' + theme.path + 'css/*.min.css' | |
], | |
tasks: [ | |
'newer:cssmin:compress', | |
] | |
}; | |
watch.solojs = { | |
files: 'build/solo/js/*.js', | |
tasks: [ | |
'newer:uglify:solojsdev', | |
'newer:uglify:solojsprod' | |
] | |
}; | |
watch.globaljs = { | |
files: ['build/global/js/*.js', 'build/global/js/**/*.js', 'build/components/**/*.js'], | |
tasks: [ | |
'concat:appjs', | |
'uglify:appjs' | |
] | |
}; | |
// CSS COMPLILATION ====================================/ | |
//solo files, compiled to /css/file.css | |
sass.solo = { | |
options:{ | |
includePaths: require('node-bourbon').with('build'), | |
sourceComments: true, | |
style: 'expanded' // compile in expanded format with comments for dev | |
}, | |
files: [{ | |
expand: true, | |
src: watch.solocss.files, // where it's coming from | |
dest: theme.path + 'css', // where it's going | |
flatten: true, // removes folder tree | |
ext: '.css', // what file extension to give it - standard | |
extDot: 'last' | |
}] | |
}; | |
// app scss files, compiled individually to /css/build/... | |
sass.app = { | |
options:{ | |
includePaths: require('node-bourbon').with('build'), | |
style: 'expanded', // compile in expanded format with comments for dev | |
sourceComments: 'normal', line_numbers: true, line_comments: true, debug_info: true, source_comments: true // none of these work :( | |
}, | |
files: [{ | |
//cwd: 'build', | |
expand: true, | |
src: watch.appcss.files, // where it's coming from | |
dest: theme.path + 'css', // where it's going | |
ext: '.css' // what file extension to give it - standard | |
}] | |
}; | |
// concat app.css files | |
concat.appcss = { | |
src: [ | |
theme.path + 'css/build/global/css/**/*.css', | |
theme.path + 'css/build/global/css/*.css', | |
theme.path + 'css/build/components/**/*.css' | |
], | |
dest: theme.path + 'css/app.css', | |
seperator: '\n' | |
}; | |
// create compressed version of all css files for prod | |
cssmin.compress = { | |
files: [{ | |
expand: true, | |
cwd: theme.path + 'css/', | |
src: ['*.css', '!*.min.css', '!editor.css'], | |
dest: theme.path + 'css/', | |
ext: '.min.css', | |
extDot: 'last' | |
}] | |
} | |
// JAVASCRIPT COMPLILATION ============================/ | |
// concat app.js files | |
concat.appjs = { | |
src: [ | |
'build/global/js/global.js', | |
'build/components/**/js/*.js' | |
], | |
dest: theme.path + 'js/app.js', | |
separator: ';' | |
}; | |
// minify app.js | |
uglify.appjs = { | |
files: {} | |
}; | |
uglify.appjs.files[theme.path + 'js/app.min.js'] = [ | |
theme.path + 'js/app.js' | |
]; | |
// uglify solo files for dev | |
uglify.solojsdev = { | |
options: { | |
compress: false, | |
mangle: false, | |
beautify: true | |
}, | |
files: [{ | |
expand: true, | |
flatten: true, // removes folder tree | |
src: watch.solojs.files, | |
dest: theme.path + 'js/' | |
}] | |
}; | |
// uglify + minify solo files for prod | |
uglify.solojsprod = { | |
options: { | |
compress: true | |
}, | |
files: [{ | |
expand: true, | |
flatten: true, // removes folder tree | |
src: watch.solojs.files, | |
dest: theme.path + 'js/', | |
ext: '.min.js', | |
extDot: 'last', | |
}] | |
}; | |
// IMAGE OPTIMISATION ==========================/ | |
imageoptim = { | |
optimise: { | |
src: ['images'] | |
} | |
} | |
// GRUNT ======================================/ | |
grunt.initConfig({ | |
pkg: grunt.file.readJSON('package.json'), | |
watch: watch, | |
sass: sass, | |
concat: concat, | |
cssmin: cssmin, | |
uglify: uglify, | |
imageoptim: imageoptim | |
}); | |
// DEPENDENT PLUGINS =========================/ | |
grunt.loadNpmTasks('grunt-contrib-watch'); | |
grunt.loadNpmTasks('grunt-contrib-cssmin'); | |
grunt.loadNpmTasks('grunt-sass'); | |
grunt.loadNpmTasks('grunt-contrib-uglify'); | |
grunt.loadNpmTasks('grunt-contrib-concat'); | |
grunt.loadNpmTasks('grunt-imageoptim'); | |
grunt.loadNpmTasks('grunt-newer'); | |
// TASKS =====================================/ | |
grunt.registerTask('default', [ | |
'skin', | |
'sass', | |
'concat', | |
'newer:cssmin', | |
'newer:uglify', | |
'watch' | |
]); | |
grunt.registerTask('imgoptim', [ | |
'imageoptim' | |
]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment