assemble / assemble-less

Grunt task for compiling LESS to CSS. This task does for less what Assemble does for HTML, making it much easier to modularize and reduce repetition in stylesheets.
http://github.com/assemble/assemble/
MIT License
66 stars 20 forks source link

assemble-less NPM version Build Status

Compile LESS to CSS. Adds experimental features that extend Less.js for maintaining UI components and themes. From Jon Schlinkert, core team member of Less.js.

This project is a fork of the popular grunt-contrib-less by the talented Tyler Kellen. Please use that plugin if you require something stable and dependable.

Getting Started

This plugin requires Grunt ~0.4.2

If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

npm install assemble-less --save-dev

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

grunt.loadNpmTasks('assemble-less');

Less task

Run this task with the grunt less command.

Task targets, files and options may be specified according to the grunt Configuring tasks guide.

Options

lessrc

Type: String

Default: null

A convenience option for externalizing task options into a .lessrc or .lessrc.yml file. If this file is specified, options defined therein will be used.

globalVars

Type: Object

Default: undefined

Prepend variables to source files.

modifyVars

Type: Object

Default: undefined

Append variables to source files.

metadata

Type: String|Array

Default: Empty string

Pass metadata as context to Lo-Dash templates embedded in LESS files. The name of the files is used as the first path in the template variables, so if you want to use data from palette.yml, your templates would look something like: <%= palette.foo %>.

Data may be formatted in JSON, YAML. See this YAML example and this LESS example.

Note that data passed into options.metadata is merged at the task and target levels. You can turn this off by adding options: {merge: false}, which then disables merging and allows targets to override any data passed in at the task-level.

imports

Type: Object (each option accepts a String or Array)

Default: null

Prepend @import statements to src files using any of the new @import directives released after Less.js v1.5.0, less, css, inline, reference (multiple and once probably aren't applicable here, but feel free to use them if you find a use case). See examples.

Any new import directives will be immediately available upon release by Less.js.

process

Type: Boolean|Object

Default: false

Process source files as templates before concatenating.

(Default processing options are explained in the grunt.template.process documentation)

banner

Type: String

Default: Empty string

This string will be prepended to the beginning of the concatenated output. It is processed using grunt.template.process, using the default options.

(Default processing options are explained in the grunt.template.process documentation)

stripBanners

Type: Boolean|Object

Default: false

Strip JavaScript banner comments from source files.

paths

Type: String|Array

Default: Directory of input file.

Specifies directories to scan for @import directives when parsing. The default value is the directory of the specified source files. In other words, the paths option allows you to specify paths for your @import statements in the less task as an alternative to specifying a path on every @import statement that appears throughout your LESS files. So instead of doing this:

@import "path/to/less/files/mixins.less";

you can do this:

@import "mixins.less";
rootpath

Type: String

Default: ""

A path to add on to the start of every url resource.

compress

Type: Boolean

Default: false

Compress output by removing some whitespaces.

cleancss

Type: Boolean

Default: false

Compress output using clean-css.

ieCompat

Type: Boolean

Default: true

Enforce the css output is compatible with Internet Explorer 8.

For example, the data-uri function encodes a file in base64 encoding and embeds it into the generated CSS files as a data-URI. Because Internet Explorer 8 limits data-uris to 32KB, the ieCompat option prevents less from exceeding this.

optimization

Type: Integer

Default: null

Set the parser's optimization level. The lower the number, the less nodes it will create in the tree. This could matter for debugging, or if you want to access the individual nodes in the tree.

strictImports

Type: Boolean

Default: false

Force evaluation of imports.

strictMath

Type: Boolean

Default: false

When enabled, math is required to be in parenthesis.

strictUnits

Type: Boolean

Default: false

When enabled, less will validate the units used (e.g. 4px/2px = 2, not 2px and 4em/2px throws an error).

syncImport

Type: Boolean

Default: false

Read @import'ed files synchronously from disk.

dumpLineNumbers

Type: String

Default: false

Configures -sass-debug-info support.

Accepts following values: comments, mediaquery, all.

relativeUrls

Type: Boolean

Default: false

Rewrite urls to be relative. false: do not modify urls.

customFunctions

Type: Object

Default: none

Define custom functions to be available within your LESS stylesheets. The function's name must be lowercase and return a primitive type (not an object or array). In the function definition, the first argument is the less object, and subsequent arguments are from the less function call. Values passed to the function are not simple primitive types, rather types defined within less. See the LESS documentation for more information on the available types.

report

Choices: false|'min'|'gzip'

Default: false

Either do not report anything, report only minification result, or report minification and gzip results. This is useful to see exactly how well Less is performing, but using 'gzip' can add 5-10x runtime task execution.

Example ouput using 'gzip':

Original: 198444 bytes.
Minified: 101615 bytes.
Gzipped:  20084 bytes.

sourceMap

Type: Boolean

Default: false

Enable source maps.

sourceMapFilename

Type: String

Default: none

Write the source map to a separate file with the given filename.

sourceMapURL

Type: String

Default: none

Override the default url that points to the sourcemap from the compiled css file.

sourceMapBasepath

Type: String

Default: none

Sets the base path for the less file paths in the source map.

sourceMapRootpath

Type: String

Default: none

Adds this path onto the less file paths in the source map.

outputSourceFiles

Type: Boolean

Default: false

Puts the less files into the map instead of referencing them.

version

Type: String

Default: less (current release)

Specify the directory containing the version of Less.js to use for compiling. You may specify a version at the task level or a different version for each target.

less: {
  options: {
    version: 'vendor/less'
  },
  styles: {
    files: {
      'css/style.css': ['src/style.less']
    }
  }
}

Useful for testing new features included in a beta or alpha release, or for comparing the compiled results from different versions of Less.js.

Usage Examples

Basic config for compiling LESS to CSS.

less: {
  development: {
    options: {
      paths: ["assets/css"]
    },
    files: {
      "path/to/result.css": "path/to/source.less"
    }
  },
  production: {
    options: {
      paths: ["assets/css"],
      compress: true
    },
    files: {
      "path/to/result.css": "path/to/source.less"
    }
  }
}

lessrc

A .lessrc file must contain valid JSON and look something like this:

{
  "compress": true,
  "metadata": "src/*.{json,yml}",
  "paths": ["vendor/bootstrap/less"]
}

A .lessrc.yml must contain valid YAML and look something like this:

compress: true
paths:
- vendor/bootstrap/less

Import directives

Prepend @import statements to src files using any of the new @import directives released after Less.js v1.5.0.

Options are:

less: {
  options: {
    paths: 'vendor/bootstrap/less',
    imports: {
      reference: ['variables.less', 'mixins.less'],
      inline: ['normalize.css'],
      less: ['normalize.css'],
      css: ['foo.css', 'bar.css']
    }
  },
  files: {}
}

Compile individual bootstrap components

Use import directives to compile each Bootstrap's LESS components separately.

Using the imports: {} option and the "files array format" enables us to compile each Bootstrap LESS component without having to add @import "variables.less"; and @import "mixins.less"; to every file.

less: {
  options: {
    paths: 'vendor/bootstrap/less',
    imports: {
      reference: ['variables.less', 'mixins.less'],
    }
  },
  components: {
    files: [
      { expand: true, cwd: 'vendor/bootstrap/less', src: '*.less', dest: 'assets/css/', ext: '.css' }
    ]
  }
}

Pass metadata to Lo-Dash templates

Use the metadata option to pass context to Lo-Dash templates before compiling. For example, let's say you have a config like this:

less: {
  options: {
    metadata: 'src/*.{json,yml}'
  },
  styles: {
    files: {
      'css/style.css': ['src/style.less']
    }
  }
}

and a data file, palette.yml, with some variables defined:

## palette.yml
info:    '#000'
warning: '#111'
danger:  '#222'
success: '#333'

Then in our LESS file:

// Use as values to variables
@palette-info:    <%= palette.info %>;
@palette-warning: <%= palette.warning %>;

.swatch-info {
  background: @palette-info;
}
.swatch-warning {
  background: @palette-warning;
}

// or directly as variables
.swatch-danger {
  background: <%= palette.danger %>;
}
.swatch-success {
  background: <%= palette.success %>;
}

Release History

Authors

This project is a fork of the popular grunt-contrib-less by Tyler Kellen. Please use that plugin if you require something stable and dependable.

This fork is maintained by:

Jon Schlinkert

Brian Woodward

License

Copyright (c) 2014 Jon Schlinkert, contributors. Released under the MIT license


This file was generated by grunt-readme on Wednesday, January 1, 2014.