npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

grunt-csstree

v0.1.3

Published

Manage dependencies between your CSS files.

Readme

grunt-csstree

Manage dependencies between your CSS files.

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.

To install the module:

npm install grunt-csstree --save-dev

Include the task in your Gruntfile:

grunt.loadNpmTasks('grunt-csstree');

Informations

Csstree allows you to fragment and mutualise your CSS, manage the inclusions of them but without writing any @import. It doesn't add anything to the syntax, it's fully compliant and compatible with all different tools around CSS.

Basically, Csstree writes @import for you, based on the files/directories structure of your project. Because of the use of @import rules, Csstree should always be combined with some kind of minification in order to not slow down page load.

How it works

Csstree generates a file branch.gen.css in every directory contained in a given root. Each file will have @import declarations of

  1. ../branch.gen.css
  2. All files within this directory, but not subdirectories

The structure is recursive! Inclusions are going upward.

Take a moment to think of it ;)

Example

index.html
css
+-- index
|   +-- index.css
+-- articles
|   +-- templates.css
|   +-- edit
|       +-- edit.css
+-- menus.css
+-- reset.css

By adding <link rel="stylesheet" href="css/index/branch.gen.css"> to index.html, you will import menus.css, reset.css and index.css.

You get it, css/acticles/branch.gen.css would import menus.css, reset.css and templates.css but not edit.css.

css/acticles/edit/branch.gen.css would import menus.css, reset.css, templates.css and edit.css.

This is a very convenient way to organise CSS. Note that the order of imports matters, CSS overriding becomes much clearer because only subdirectories can override.

Usage

Basic setup using grunt-contrib-cssmin

As mentionned above, using branch.gen.css directly is practial for developing but should be replaced in production. We are going to minify our branch.gen.css into branch.gen.min.css. We let you figure out how to do the switch because it depends a lot on how you manage deployment, configurations etc ...

grunt.initConfig({
  csstree: {
    clientProject: {
      src: 'css/' // The root of your css tree
    }
  },
  cssmin: {
    minifyBranches: {
      expand: true,
      src: ['css/**/branch.gen.css'],
      ext: '.min.css',
      extDot: 'last'
    }
  }
});

src must be a single directory. Csstree is a multi-task, so if you want to build several trees, then define several targets.

Csstree excludes file names that contain .gen, so please keep .gen on minified files so they won't be processed by further Csstree executions.

Generated files should not be commited and should be included in a clean task:

clean: ['css/**/*.gen.*']

Coupling with Less

Given that your less (or css) files are in styles/

Less doesn't resolve @import on regular css files (more details here), we revolve this simply by changing the extension of branch files:

grunt.initConfig({
  csstree: {
    lessTree: {
      options: {
        ext: '.less'
      },
      src: 'styles'
    }
  },
  less: {
    compileTree: {
      expand: true,
      src: ['styles/**/branch.gen.less'],
      ext: '.min.css',
      extDot: 'last'
    }
  }
});

Options

ext

Type: String
Default: .css

Extension of generated files branch.gen(+ext)

importFormat

Type: Function(file)
Default: return '@import "' + filename +'";'

Define the import format used in branch.gen.css. Csstree redefine it itself when using ext: '.less'

encoding

Type: String
Default: utf-8

Encoding of generated files

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. We care about clean git history as well.

Release History

  • 2014-04-07 v0.1.0 First version of Csstree