node package manager

Introducing npm Enterprise add-ons. Integrate third-party dev tools into npm…


LESS precompiler and CSS plugin for grunt-browserify


Version 0.0.1

LESS precompiler and CSS plugin for grunt-browserify. Forked from node-lessify.

When bundling an app using Browserify, it's often convenient to be able to include your CSS as a script that appends the style declarations to the head. This is particularly relevant for self-assembling apps that attach themselves to a page but otherwise have reserved real-estate on the DOM.

This small script allows you to require() your CSS or LESS files as you would any other script.

npm install grunt-less-browserify

Write your LESS or CSS files as you normally would, and put them somewhere where your script can find it.

Then simply require them as you might anything else:

module.exports = function(grunt) {
    pkg: grunt.file.readJSON('package.json'),
    browserify: {
      dist: {
        files: {
          'build.js': ['main.js']
        options: {
            transform: ['grunt-less-browserify'],
    lessBrowserify: {
        imports: ['helpers.less'],
        output:  'dist/word.css',
        jsAppend: false
  • imports: A list of files that should be imported before compiling every less file. This is very useful for less helper libraries.
  • output: An output file for the concatenated stylesheet.
  • jsAppend: Whether or not to add the stylesheets using javascript in the browserify output. (default true)
  • minify: Whether or not to minify the CSS output. Defaults to true unless specified false.

The stylesheets are compiled (in the case of LESS), minified, and bundle into a function that creates a new <style> element and appends it to the <head> using native Javascript.

LESS allows one to @import other LESS files. This module synchronously imports those dependencies at the time of the bundling. It looks for the imported files in both the directory of the parent file and the folder where the module itself lives, so it should work so long as the paths in the @import commands are correct relative to the importing file, as usual. It is not currently tested for recursive importing.