How To Use Bower Scss With Jekyll
Include any scss from bower
Overview
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.
Process
into /css/CSS-FILE in each build]
Setup
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.
In this tutorial the Bootstrap 4 bower package is structured as:
bower_components/bootstrap/
βββ 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`)
@import
"bootstrap/scss/bootstrap-flex"
;
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">
Review
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.
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]
References
- Assets Jekyll docs https://jekyllrb.com/docs/assets/
- Bower docs https://bower.io/
- Multilingual Jekyll Without PluginsMay 8, 2017
- Host a Jekyll Website With Pretty Urls In Amazon S3 and CloudfrontApril 24, 2017
- Get A List Of Categories Based In Subfolders In JekyllMarch 3, 2017
- 5 Steps To Add Bootstrap 4 To Jekyll The Right WayFebruary 27, 2017
- Automated Deployment Of Jekyll Websites To Github Pages With A Git Push To GithubNovember 8, 2016
- How To Use Bower Scss With Jekyll
- How to implement breadcrumbs on a Jekyll site with nested categoriesJune 7, 2016
- How To Handle Adsense In A Jekyll Development EnvironmentJune 6, 2016
- How To Prevent Content Displaying In A Jekyll Development EnvironmentJune 6, 2016
Articles
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
·