Search code examples
importmixinsstylus

Using a mixin/function to poplulate @import paths in Stylus


I was hoping to be able to do something like the following in Stylus:

variables (spec)
  "../" + spec + "/css/variables.styl"

@import variables(button);
@import variables(form);
..

There is reasoning for the file structure I am just trying to make it easier to manage the repetition in this file rather than having to write:

@import "../button/css/variables.styl"
@import "../form/css/variables.styl"
..

But when I try the Stylus compiler errors with "@import string expected"


Solution

  • Well, you just need to remove the space before (), otherwise the declaration is parsed as a selector:

    variables(spec)
      "../" + spec + "/css/variables.styl"
    
    @import variables(button);
    @import variables(form);