O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Mastering Grunt

Book Description

If you’re tired of repetitive JavaScript tasks like minification, compilation, and testing, this book will teach you how to use Grunt to automate them. Learn in easy steps how to streamline your workflow when building any web application.

In Detail

Grunt.js continues to excel as the build automation tool of choice. Along with its support for many third-party technologies, Grunt is packaged with a clean API for defining tasks. This powerful tool can streamline your workflow by automating the preparation tasks for production, such as compression, compilation, obfuscation, testing, and even pushing your web application live. This book will teach you how to master build automation and testing with Grunt. You will have the opportunity to utilize the latest and in-demand web tools, such as Git, Jade, CoffeeScript, Sass, and the Mocha testing engine, across several exciting projects by combining Grunt with them. You will also learn to create a project – a simple Bulletin Board System (BBS), which will explain the use of Grunt alongside the Mocha testing library to automate testing throughout the build process.

Mastering Grunt will demonstrate how to leverage Grunt with other technologies to become an expert in build automation, teaching you the best practices for modern web development along the way.

What You Will Learn

  • Build any web application using Grunt.js
  • Explore the basics revolving around source control with Git
  • Understand the importance behind package management with npm and Bower
  • Use Grunt alongside Jade, the templating engine, to automate the compression and obfuscation process
  • Ease the compilation process by working with Sass, a CSS preprocessor
  • Understand the fundamentals involved in CoffeeScript development
  • Implement headless testing using Mocha, a JavaScript-based testing engine
  • Automate the frontend testing process using Grunt

Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.

Table of Contents

  1. Mastering Grunt
    1. Table of Contents
    2. Mastering Grunt
    3. Credits
    4. About the Author
    5. About the Reviewers
    6. www.PacktPub.com
      1. Support files, eBooks, discount offers, and more
        1. Why subscribe?
        2. Free access for Packt account holders
    7. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. Conventions
      5. Reader feedback
      6. Customer support
        1. Errata
        2. Piracy
        3. Questions
    8. 1. Getting Started
      1. Introducing Grunt
        1. Plugins and Gruntfile.js
        2. Dissecting the Gruntfile.js configuration file
          1. Constants and functions
          2. Configuration
          3. User-defined tasks
      2. Introducing Git
        1. Using Git
        2. Installing Git
          1. Installing Git on Windows
          2. Installing Git on Mac OS X
          3. Installing Git on Linux
        3. Git basics
      3. Introducing GitHub
        1. Using GitHub
        2. Installing GitHub
      4. Introducing npm
        1. Why use npm?
        2. Installing npm
          1. Installing npm on Windows
          2. Installing npm on Mac OS X and Linux
        3. Using npm
      5. Introducing Bower
        1. Using Bower
        2. Installing Bower
        3. Bower basics
      6. Installing Grunt
        1. Installation steps
        2. Troubleshooting
          1. Grunt: command not found
          2. Fatal error: Unable to find local grunt
      7. Deploying a Hello World page
      8. Summary
    9. 2. Developing a Blog with Jade and Sass
      1. A brief summary of Jade
      2. A brief summary of Sass
        1. What is Sass?
      3. Concatenation and minification
      4. Building the blog
        1. Installing the required Grunt plugins
        2. Configuring grunt-contrib-watch
        3. Developing the blog
        4. Implementing the custom build Grunt task
      5. Summary
    10. 3. Making an Employee Management System
      1. A brief summary of CoffeeScript
      2. Building the employee management system
        1. Installing the required Grunt plugins
        2. Configuring grunt-contrib-watch
        3. Developing the employee management system
        4. Implementing the custom build Grunt task
      3. Summary
    11. 4. Final Project – Simple Bulletin Board System
      1. Installing the required Grunt plugins
        1. Configuring grunt-contrib-watch
      2. Developing a simple Bulletin Board System (BBS)
        1. Writing Mocha tests using Zombie and Assert
        2. Implementing the custom test Grunt task
        3. Implementing the custom build Grunt task
      3. Summary
    12. 5. Best Practices for Modern Web Applications
      1. The importance of search engine optimization
        1. Item 1 – using keywords effectively
        2. Item 2 – header tags are powerful
        3. Item 3 – make sure to have alternative attributes for images
        4. Item 4 – enforcing clean URLs
        5. Item 5 – backlink whenever safe and possible
        6. Item 6 – handling HTTP status codes properly
        7. Item 7 – making use of your robots.txt and site map files
        8. Using Grunt to reinforce SEO practices
      2. Form validation in the modern web world
        1. Item 8 – using client-side validation over error pages
        2. Item 9 – differentiating required and optional information
        3. Item 10 – avoiding confusing fields
        4. Item 11 – using confirmation fields for pertinent data
        5. Item 12 – using custom inputs for complex data types
        6. Item 13 – preventing autovalidation with CAPTCHAs
        7. Item 14 – reinforcing data integrity with server-side validation
        8. Using Grunt to automate form testing
      3. Designing interfaces for the mobile generation
        1. Item 15 – designing preemptively with mobile in mind
        2. Item 16 – lazy load content using JavaScript
        3. Item 17 – defer parsing of JavaScript
        4. Using Grunt to reduce page load time
      4. Summary
    13. Index