Created
April 12, 2013 05:55
-
-
Save anonymous/5369760 to your computer and use it in GitHub Desktop.
Gruntfile i am using for a current project with two main tasks, grunt and grunt dev. The default task is for when you're working on a project to see live changes. Grunt dev is for deployment
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) { | |
'use strict'; | |
// Project configuration. | |
grunt.initConfig({ | |
pkg: grunt.file.readJSON('package.json'), | |
asmblconfig: grunt.file.readJSON('config/assemble.json'), | |
csslintlconfig: grunt.file.readJSON('config/csslint.json'), | |
// ### clean | |
// grunt-contrib-clean npm task | |
// Deletes the <string> paths in the array | |
clean: { | |
clean: ['build', 'reports'] | |
}, | |
// ### compass | |
// grunt-contrib-compass npm task | |
// Builds the SASS files into CSS | |
compass: { | |
dev: { | |
options: { | |
config: 'config/compass.rb', | |
noLineComments: false, | |
environment: 'development', | |
debugInfo: true | |
} | |
}, | |
dist: { | |
options: { | |
config: 'config/compass.rb', | |
noLineComments: true, | |
environment: 'production', | |
debugInfo: false | |
} | |
} | |
}, | |
// Templates, config HTML docs from .hbs files | |
assemble: { | |
options: { | |
engine: 'handlebars', | |
helpers: '<%= asmblconfig.helpers %>', | |
docs: true, | |
production: false, | |
flatten: true, | |
assets: 'build/assets', | |
data: [ | |
'src/hbr/data/**/*.json' | |
] | |
}, | |
pages: { | |
options: { | |
layout: 'src/hbr/layouts/layout.hbs', | |
partials: [ | |
'src/hbr/partials/**/*.hbs' | |
] | |
}, | |
files: { | |
// Compile each page in the project. | |
'build': [ | |
'src/hbr/pages/**/*.hbs' | |
] | |
} | |
} | |
}, | |
// ### copy | |
// grunt-contrib-copy npm task | |
// Copies files from the src folder to build | |
copy: { | |
build: { | |
expand: true, | |
cwd: 'src/assets/', | |
src: ['img/**/*', "js/**/*", "polyfil/**/*", "font/**/*", "!img/sprite/**/*", "!img/sprite"], | |
dest: 'build/assets/' | |
}, | |
dev: { | |
expand: true, | |
cwd: 'src/assets/', | |
src: ['img/**/*', "polyfil/**/*", "font/**/*", "!img/sprite/**/*", "!img/sprite"], | |
dest: 'build/assets/' | |
}, | |
data: { | |
expand: true, | |
cwd: 'src/data/', | |
src: ['*'], | |
dest: 'build/data/' | |
}, | |
livedit: { | |
expand: true, | |
cwd: 'src/assets/', | |
src: ['**/*'], | |
dest: 'build/assets/' | |
} | |
}, | |
// ### jshint | |
// JSHint options for the lint task | |
// Runs a lint and coding standards check against the Javascript | |
// | |
jshint: { | |
jshintrc: 'config/jshint.json', | |
all: ['src/assets/js/main.js', 'src/assets/js/build/**/*', 'src/data/*', '!src/data/*.html'] | |
}, | |
// ### watch | |
// Executes the listed targets on file save | |
// Watches folders for file changes and then runs the specified tasks | |
watch: { | |
jshint: { | |
files: '<%= jshint.all %>', | |
tasks: ['jshint'], | |
options: { | |
interrupt: true | |
} | |
}, | |
compass: { | |
files: 'src/sass/**/*', | |
tasks: ['compass:dev'], | |
options: { | |
interrupt: true | |
} | |
}, | |
assemble: { | |
files: 'src/hbr/**/*', | |
tasks: ['assemble'], | |
options: { | |
interrupt: true | |
} | |
}, | |
copy: { | |
files: ['src/assets/font/**/*', 'src/assets/polyfil/**/*', 'src/assets/img/**/*', 'src/assets/js/**/*'], | |
tasks: ['copy:livedit'], | |
options: { | |
interrupt: true | |
} | |
}, | |
data: { | |
files: ['src/data/**/*'], | |
tasks: ['copy:data'], | |
options: { | |
interrupt: true | |
} | |
} | |
}, | |
imagemin: { | |
uat: { | |
options: { | |
optimizationLevel: 7 | |
}, | |
files: [{ | |
expand: true, | |
cwd: 'build/assets/img', | |
src: ['*.{png,jpg,jpeg}', '**/*.{png,jpg,jpeg}'], | |
dest: 'build/assets/img' | |
}] | |
} | |
}, | |
// ### Plato | |
// Generates a complexity report on the project JavaScript | |
plato: { | |
plato: { | |
files: { | |
'reports/plato': ['src/assets/js/main.js', 'src/assets/js/build/*.js', 'test/**/*.js'] | |
} | |
} | |
}, | |
requirejs: { | |
compile: { | |
options: { | |
baseUrl : 'src/assets/js', | |
mainConfigFile: 'src/assets/js/main.js', | |
keepBuildDir : false, | |
optimize : 'uglify2', | |
dir : 'build/assets/js', | |
generateSourceMaps: true, | |
preserveLicenseComments: false, | |
useStrict : true, | |
removeCombined: true, | |
modules : [ | |
{ | |
name: 'main', | |
include: ['OAGeneral', 'OASlideNav', 'fitvids', 'sharrre', 'OALoadMore', 'OASlideshow', 'hammer'] | |
}, | |
{ | |
name: 'OAMap', | |
exclude: ['jquery'] | |
}, | |
{ | |
name: 'flexslider', | |
exclude: ['jquery'] | |
} | |
] | |
} | |
} | |
}, | |
// ### connect | |
// Runs a local server | |
connect: { | |
build: { | |
options: { | |
port: 8080, | |
base: 'build' | |
} | |
} | |
} | |
}); | |
// Load plugins | |
grunt.loadNpmTasks('grunt-contrib-clean'); | |
grunt.loadNpmTasks('grunt-contrib-compass'); | |
grunt.loadNpmTasks('grunt-contrib-copy'); | |
grunt.loadNpmTasks('grunt-contrib-jshint'); | |
grunt.loadNpmTasks('grunt-contrib-watch'); | |
grunt.loadNpmTasks('assemble'); | |
grunt.loadNpmTasks('grunt-contrib-connect'); | |
grunt.loadNpmTasks('grunt-contrib-imagemin'); | |
grunt.loadNpmTasks('grunt-plato'); | |
grunt.loadNpmTasks('grunt-contrib-requirejs'); | |
// Load local tasks from project root. | |
grunt.loadTasks('node_modules/assemble/tasks'); | |
// Default task. | |
grunt.registerTask('default', ['clean', 'jshint:all', 'copy:build', 'copy:data', 'compass:dev', 'assemble', 'connect:build', 'watch']); | |
grunt.registerTask('dev', ['clean', 'jshint:all', 'copy:dev' , 'copy:data', 'compass:dist', 'assemble', 'requirejs', 'imagemin:uat']); | |
grunt.registerTask('report', ['plato']); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment