On Github basis42 / grunt.js_talk
Entwickelt wird grunt.js von Ben Alman, die Projektwebsite unter gruntjs.com sagt:
Grunt is a task-based command line build tool for JavaScript projectsCSS und Javascript
mario@ubuntu:~/sudo npm install -g grunt-cli mario@ubuntu:~/sudo npm install grunt
besteht im Wesentlichen aus:
Verwaltung von Dependancies / Plugins via npm
Beispiel package.json:
{ "name": "Build_example_app", "version": "0.1.0", "dependencies": { "grunt": "~0.4", "grunt-contrib-watch" : "~0.5", "grunt-contrib-uglify" : "~0.2", "grunt-contrib-cssmin" : "~0.4", "grunt-contrib-sass" : "https://github.com/basis42/grunt-..." } }
module.exports = function(grunt) { // Project configuration. grunt.initConfig({ cssmin : { compress : { files : {'../css/all.min.css' : ['../css/all.css']} } } }); grunt.loadNpmTasks('grunt-contrib-cssmin'); grunt.registerTask('default', ['cssmin']); };
mario@ubuntu:~/grunt.js_talk/example/build$ grunt Running "cssmin:compress" (cssmin) task File ../css/all.min.css created. Uncompressed size: 743 bytes. Compressed size: 244 bytes gzipped (696 bytes minified). Done, without errors. mario@ubuntu:~/grunt.js_talk/example/build$
module.exports = function(grunt) { grunt.initConfig({ lint : { files : [ 'grunt.js', '../js/**/*.js' ] }, watch : { options : { livereload : true, spawn: false }, css : { files : ['../css/**/*.scss'], tasks : ['sass', 'cssmin'] }, js : { files : ['../js/**/*.js'], tasks : 'min' } }, uglify : { js : { files : {'../js/app.min.js' : ['../js/app.min.js']} } }, sass : { scss : { options : { debugInfo : true, lineNumber : true }, files : {'../css/all.css' : ['../css/main.scss']} } }, cssmin : { compress : { files : {'../css/all.min.css' : ['../css/all.css']} } } }); grunt.loadNpmTasks('grunt-contrib-watch'); grunt.loadNpmTasks('grunt-contrib-sass'); grunt.loadNpmTasks('grunt-contrib-cssmin'); grunt.loadNpmTasks('grunt-contrib-uglify'); grunt.loadTasks('example-local-plugin/tasks'); grunt.registerTask('default', ['sass', 'cssmin', 'uglify']); };
mario@ubuntu:~/grunt.js_talk/example/build$ grunt Running "sass:scss" (sass) task Running "cssmin:compress" (mincss) task File ../css/all.min.css created. Uncompressed size: 743 bytes. Compressed size: 244 bytes gzipped (696 bytes minified). Running "uglify:js" (uglify) task File "../js/app.min.js" created. Uncompressed size: 75 bytes. Compressed size: 85 bytes gzipped (75 bytes minified). Done, without errors. mario@ubuntu:~/grunt.js_talk/example/build$
Gruntfile.js:
// local defined taks grunt.loadTasks('example-local-plugin/tasks');
example-local-plugin/tasks/example.tasks.js:
'use strict'; module.exports = function(grunt) { grunt.registerTask('hello', 'Write greeting to console.', function(){ console.log('Hello! This is the hello task!'); }); };