140 likes | 410 Views
Grunt. introduction. The problem. Complexity Growing number of assets Increasing functionality Technology Code comments and code style Code validation and unit tests Portability (configure once and share) Agile Frequent deliveries. The JavaScript Task Runner.
E N D
Grunt introduction
The problem • Complexity • Growing number of assets • Increasing functionality • Technology • Code comments and code style • Code validation and unit tests • Portability (configure once and share) • Agile • Frequent deliveries
Ok, what can I do with Grunt? • LESS/SASS code compilation; • CSS or JavaScript files concatenation; • JavaScript minification; • JavaScript code check with JS Hint; • HTML and CSS code validation with w3c validators; • PHP code execution; • File operations (move/copy/delete/archive); • And aprrox. 2,265 more usecases
Setting-up Grunt project • Install Node.js • Install grunt-clinpminstall -g grunt-cli • Create package.json • Create Gruntfile.js • Use it by simply callinggrunt <task-name>
package.json • { • "name": "my-project-name", • "version": "0.1.0", • "devDependencies": { • "grunt": "~0.4.2", • "grunt-contrib-jshint": "~0.6.3", • "grunt-contrib-nodeunit": "~0.2.0", • "grunt-contrib-uglify": "~0.2.2" • } • }
Gruntfile.js • module.exports = function(grunt) { • // Project configuration. • grunt.initConfig({ • pkg: grunt.file.readJSON('package.json'), • uglify: { • /*** task config here ***/ • } • }); • // Load the plugin that provides the "uglify" task. • grunt.loadNpmTasks('grunt-contrib-uglify'); • // Default task(s). • grunt.registerTask('default', ['uglify']); • };
Uglify task • uglify: { • options: { • banner: '/*! Our license data */\n' • }, • build: { • src: 'src/application.js', • dest: 'build/application.min.js' • } • }
JS Hint task • jshint: { • src: [ • 'Gruntfile.js', • 'js/application.js', • ], • options: { • jquery: true, • globals: { • brightcove: true • } • } • }
HTML validation task • 'html-validation': { • options: { • reset: true, • stoponerror: false, • relaxerror: [ • "Document uses the Unicode Private Use Area(.*)" • ], //ignores these errors, • }, • files: { • src: ['build/*.html'] • } • },
Sequencing tasks • module.exports = function(grunt) { • // Project configuration. • grunt.initConfig(/* tasks config here */); • // Load the plugins that provides necessary tasks. • grunt.loadNpmTasks('grunt-contrib-uglify'); • // Default task(s). • grunt.registerTask('default', ['jshint','compass','copy','build','compress']) • }; • And then let the magic go • grunt
Questions? • github: @aboritskiy • twitter: @anton_boritskiy