Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added @import index resolution support

  • Loading branch information...
commit a5c0099779ffea0d28c305d422b04732ddb20352 1 parent ab9935e
TJ Holowaychuk tj authored
Showing with 10 additions and 1 deletion.
  1. +8 −0 docs/
  2. +2 −1  lib/visitor/evaluator.js
8 docs/
@@ -18,6 +18,14 @@ will render to the literal css __@import__ shown below:
When using __@import__ without the `.css` extension, it is assumed to be a Stylus sheet, for example `@import "mixins/border-radius"`.
__@import__ works by iterating an array of directories, and seeing if this file lives in any of them, similar to node's `require.paths`. This array defaults to a single path which is derived from the `filename` option's dirname. So if your filename is `/tmp/testing/stylus/main.styl`, then import will look in `/tmp/testing/stylus/`.
+ __@import__ also supports index styles, meaning if you `@import blueprint`, it will resolve either `blueprint.styl` or `blueprint/index.styl`, useful for libraries to expose all of their features, but still allow a subset of the library to be imported. For example a common lib structure might be:
+ ./tablet
+ |-- index.styl
+ |-- vendor.styl
+ |-- buttons.styl
+ |-- images.styl
In the example below we set the `paths` options to provide additional paths to Stylus. Within `./test.styl` we could then `@import "mixins/border-radius"` or `@import "border-radius"` since `./mixins` is exposed to Stylus.
3  lib/visitor/evaluator.js
@@ -517,7 +517,7 @@ Evaluator.prototype.visitImport = function(import){
, root = this.root
, i = this.rootIndex
, stylus = require('../stylus')
- , path = import.path
+ , path = name = import.path
, relative = this.importPath;
// Literal
@@ -527,6 +527,7 @@ Evaluator.prototype.visitImport = function(import){
// Lookup
if (relative) this.paths.push(relative);
found = utils.lookup(path, this.paths, this.filename);
+ found = found || utils.lookup(name + '/index.styl', this.paths, this.filename);
if (relative) this.paths.pop();
// Throw if import failed
Please sign in to comment.
Something went wrong with that request. Please try again.