Book Image

Grunt Cookbook

By : Jurie-Jan Botha
Book Image

Grunt Cookbook

By: Jurie-Jan Botha

Overview of this book

<p>A web application can quickly turn into a complex orchestration of many smaller components, each one requiring its own bit of maintenance. Grunt allows you to automate all the repetitive tasks required to get everything working together by using JavaScript, the most popular programming language.</p> <p>Grunt Cookbook offers a host of easy-to-follow recipes for automating repetitive tasks in your web application's development, management, and deployment processes. This book will introduce you to methods that can be used to automate basic processes and your favorite tools. By following the recipes, you will soon be comfortable using Grunt to perform a wide array of advanced tasks in a range of different scenarios.</p>
Table of Contents (17 chapters)
Grunt Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Defining custom functions with LESS


In this recipe, we'll make use of the contrib-less (0.11.4) plugin to define custom functions that can be used in our LESS style sheets.

For our example, we'll create a custom function called halfDarken, which will darken any color provided to it by 50 percent. It will make use of the LESS library's built-in darken function.

Getting ready

In this example, we'll work with the basic project structure that we created in the Compiling LESS to CSS recipe of this chapter. Be sure to refer to it if you are not yet familiar with its contents.

How to do it...

The following steps will take us through altering our configuration to define a custom function, and altering our LESS style sheet to use it:

  1. First, we'll alter the configuration of our less task by adding the customFunctions option and defining a stub for the halfDarker function:

    less: {
      styles: {
        options: {
          customFunctions: {
            halfDarken: function (less, color) {
              return color;
        ...