1 / 13

Grunt

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.

cheryl
Download Presentation

Grunt

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Grunt introduction

  2. 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

  3. The JavaScript Task Runner

  4. 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

  5. Eh, that must be too complex to setup…I don’t have time!

  6. 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>

  7. 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" • } • }

  8. 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']); • };

  9. Uglify task • uglify: { • options: { • banner: '/*! Our license data */\n' • }, • build: { • src: 'src/application.js', • dest: 'build/application.min.js' • } • }

  10. JS Hint task • jshint: { • src: [ • 'Gruntfile.js', • 'js/application.js', • ], • options: { • jquery: true, • globals: { • brightcove: true • } • } • }

  11. 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'] • } • },

  12. 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

  13. Questions? • github: @aboritskiy • twitter: @anton_boritskiy

More Related