Skip to content

Instantly share code, notes, and snippets.

@michaek
Forked from nex3/use.scss
Last active August 29, 2015 14:07
Show Gist options
  • Save michaek/280d1bd44f91d890c73d to your computer and use it in GitHub Desktop.
Save michaek/280d1bd44f91d890c73d to your computer and use it in GitHub Desktop.
A new syntax to improve @import in Sass.

@import is one of the most useful features of Sass, but it has some shortcomings. For one, newcomers are often confused that it uses the same syntax as CSS's import, and think it does the same thing. It doesn't!

An improved import utility might:

  • Avoid overloading an existing name
  • Provide variable/mixin scoping
  • Allow importing of only some elements of an included file

Simplicity should be valued above features and options.

// Imports zip.sass, zip.scss *nontransitively* with a "zip" prefix.
@require "zip";
// Uses the "foo" mixin from zip.
@require foo from "zip";
// The prefix is now "zap".
@require "zip" as zap;
// A require without an export is just an @import, but always includes the content, even for css.
@require "zup";
// Everything in "@export" is visible to importers of this file.
@export {
$bar: ok;
@mixin foo {
}
};
i {
text-decoration: intolerable;
}
@michaek
Copy link
Author

michaek commented Oct 7, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment