How To Use Bower Scss With Jekyll

Include any scss from bower

Last modified:
Tags Git , Server , Bare-Repository


Bower makes it easier to keep up to date all the frameworks, libraries, assets, and utilities used in web development.

Jekyll automatically generates css files from scss.

This tutorial shows how to use both of them togheter, using Bootstrap-flex 4 as the example package.

This solution was based in creating symbolics links, now I prefer a newer, cleaner way to deal with this extending the directories that Jekyll uses to process SASS files in this tutorial: How to add Bootstrap 4 to Jekyll extending SASS directories.


graph TB A[$ bower update]==>|Generates CSS|B B[$ scss foo_package/style.scss css/style.css] B ==>|New package version| A
graph TB A[$ bower update]==>|Generates CSS|B B[Jekyll automatically convert Bower SCSS file
into /css/CSS-FILE in each build]


Bower by default will download its packages to a directory named /bower_components at root level.

The problem is that Jekyll uses, by default, /_sass directory to put custom .scss files, that are then processed into some file located at /css directory.

The goal is to be able to include the bower_components directories containing .scss files, into /_sass directory to be consistent with default configurations.

Bower_components directory shouldn't be included into ```/_sass``` directory directly, because they can contain a lot of different files, not only ```.scss```, like ```.js``` or ```css``` files.

In this tutorial the Bootstrap 4 bower package is structured as:

β”œβ”€β”€ dist
β”‚Β Β  β”œβ”€β”€ css
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ bootstrap.css
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ bootstrap.min.css
β”‚Β Β  └── js
β”œβ”€β”€ ...
└── scss
    β”œβ”€β”€ _alert.scss
    β”œβ”€β”€ _animation.scss
    β”œβ”€β”€ bootstrap-flex.scss
    β”œβ”€β”€ bootstrap-grid.scss
    β”œβ”€β”€ bootstrap-reboot.scss
    β”œβ”€β”€ bootstrap.scss
    β”œβ”€β”€ _breadcrumb.scss
    β”œβ”€β”€ ...
    └── _variables.scss

We want to be able to include /bower_components/bootstrap/scss/bootstrap-flex.scss in our Jekyll website, as it is not currently distributed by default as a css file in /bower_components/bootstrap/dist folder.

Generating CSS files from Bower directories

A symbolic link should be created inside /_sass pointing to the bower directory containing the .scss files.

In the base of the jekyll project:

$ ln -s bower_components/bootstrap/ _sass/bootstrap

This creates a symbolic link named bootstrap inside the /_sass directory to bower_components/bootstrap/.

To generate them automatically, Jekyll needs to have the following SCSS file in /css/bootstrap-flex.scss, so it can generate /css/bootstrap-flex.css.

@charset "utf-8";

// Import partials from `sass_dir` (defaults to `_sass`)

Each time Jekyll builds a site it will create /css/bootstrap-flex.css.

Including CSS into templates

To make the website use the newly generated CSS file, it should be included in a template like:

<link rel="stylesheet" type="text/css" href="{{ site.baseurl }}/css/bootstrap-flex.css">


This is a simple process respecting each package default directories, that makes it easy to maintain Bower packages up to date, without having to regenerate them manually with the scss command.

graph TB A[Create symbolic link from Jekyll _sass directory to
Bower package directory] B[Create a SCSS file in /css directory
to process Bower SCSS file ] A ==> B B[Include the generated CSS file from /css in a layout]


Marcelo Canina
I'm Marcelo Canina, a developer from Uruguay. I build websites and web-based applications from the ground up and share what I learn here.
comments powered by Disqus

Automatically converting SCSS files into CSS in each Jekyll build.

Clutter-free software concepts.
Translations English EspaΓ±ol

Except as otherwise noted, the content of this page is licensed under CC BY-NC-ND 4.0 . Terms and Policy.

Powered by SimpleIT Hugo Theme