Sam Weaver
Sam Weaver

Reputation: 1079

Can Sass or Less be configured to compile just certain classes?

Let's say I have a large Sass/Less project such as Bootstrap, and I want to use one single element of it, (say, a text box.) Is is possible to have Sass/Less compile just the classes needed for that, referencing whatever variables and mixins that are across multiple files, just to compile that 1 (or 2, or 5, or 10) class(es)?

Upvotes: 1

Views: 238

Answers (2)

JustH
JustH

Reputation: 1402

There currently aren't any features in Less/Sass to accommodate this. What you are looking for is a post-build process to remove unused CSS classes. The most notable currently is Uncss which has plugins available for most build tools (Gulp, Grunt, etc)

Upvotes: 2

JTerry
JTerry

Reputation: 101

You could create mixins that aren't executed immediately by adding parenthesis. In my less library, I use a node script to create an autoload.less file which I can reference.

From there, I create my final classes as:

@import "autoload.less";

.myClass {
    #myLessModule > .aMixin();
}

I don't think this is a perfect solution but it is working fairly well for me, and the resulting stylesheets do not contain excess stylings.

Upvotes: 2

Related Questions