On Github acbr / grunt-presentation
Rafael Guedes
rguedes@avenuecode.com
Avenue Code - 2014
tl;dr
in one word: automation
npm install -g grunt-cli npm install grunt --save-dev
.. and that's it :)
"devDependencies": {
"grunt": "~0.4.1",
...
All configuration code is done inside Gruntfile.js located at project root
grunt.registerTask(taskName, [description, ] taskFunction)
Ex:
module.exports = function(grunt) {
grunt.registerTask('foo', 'My "foo" task.', function(a, b) {
grunt.log.writeln(this.name, a, b);
});
}
$ grunt foo logs: "foo", undefined, undefined $ grunt foo foo:bar logs: "foo", "bar", undefined $ grunt foo:bar:baz logs: "foo", "bar", "baz"
grunt.initConfig({
jshint: {
foo: {
src: ['app/js/a.js', 'src/aa.js']
},
},
concat: {
options: {
src: ['src/bb.js', 'src/bbb.js'],
dest: 'dest/b.js',
},
},
uglify : require('path/to/my/settings'),
...
...
watch: {
options: {
interrupt: true
},
files: [
'app/js/**/*.js',
// Exclude minified files
'!app/js/min/*'
],
tasks: [
'jshint:foo', 'uglify', 'notify:uglify', 'concat',
'notify:concat', 'jdd', 'notify:jdd'
]
}
});
...
...
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-notify');
grunt.registerTask('default', ['jshint:foo', uglify', 'concat', 'watch']);
...
Remind: packages must be declared in package.json
Create a task (you are free to set its name) with following rules:
Watch for changes on you source codeIn case of .css change, launch a CSS lint task In case of .js change, launch a JS lint task Run uglify & minify tasks and move the result file(s) to /min/ Notify the user that the flow is doneThe task should FAIL if a lint rule is broken.
Submit the code on your Github account
Questions?