Devon's avatar
Level 18

Using Bootstrap, LESS, & Mixins

In the latest series, "Build Larabook From Scratch", Jeff includes Bootstrap then shows us how to automatically watch and compile SASS files...

I'd like to download Bootstrap source files in a local environment, write my own LESS with Bootstrap mixins, and then have that automatically compiled and saved to the public directory... How would I go about doing this?

I feel like this would be a better approach than chaining a bunch of bootstrap styles in the HTML...

0 likes
6 replies
RayRutjes's avatar

I recommend using bower to download the bootstrap package.

bower install bootstrap --save

Then copy paste the bootstrap.less file into your app/assets/less directory and adjust the import paths. The first line looks like:

@import "../../../bower_components/bootstrap/less/mixins.less";
Devon's avatar
Level 18

I didn't realize there was a SASS version of Bootstrap. I ended up sticking with SASS, downloaded the sources off of GitHub, put them in /app/assets and then created my main.scss file.

I've never worked with LESS or SASS before... Is there a way to use Bootstrap as more of a reference to only pull styles I fetch via mixins? Would be nice and would reduce the bloatedness of it.

I see that in LESS, I could do @import (reference)... I can't find a similar option in SASS. :-/

MattMangoni's avatar

I'm not sure if you're talking about full partials or just mixins, but still... you can take a look at http://sass-lang.com/guide and you'll see that both are possible and easy to do :)

For Mixins:

@mixin border-radius($radius) {
          border-radius: $radius;
}

.box { @include border-radius(10px); }

For Partials, create one called, for example, _navbar.scss:


@import 'navbar';

PS: notice tha lack of "_" in the import :)

Never got my hands on the SASS version of Bootstrap tho, so I can't help you on that directly :)

Devon's avatar
Level 18

Neither. I'm looking for SASS' equivalent of LESS' @import (reference) "bootstrap.less" http://lesscss.org/features/#import-options-reference

In other words, using that import statement will output absolutely nothing. However, if I have something like:

.some-box { 
    .col-sm-offset-2;
    .col-sm-10;
}

Then it will fetch and output the referenced styles.

MattMangoni's avatar

Oh, right, got it. Unfortunately, I don't think there's an equivalent for that in SASS, but I haven't used it all that much lately so I might be missing something :)

Devon's avatar
Level 18

Aww, well that stinks... Actually, for that reason alone, I think I'll go give LESS a try instead.

...unless I too am missing something.

Please or to participate in this conversation.