The steps in this guide enabled me to avoid using any CDNs and shrink my bulma CSS to just 19 KB. It also shrinks BulmaJS from 100+ Kb to ~20 Kb with a custom fork of BulmaJS that only builds the navbar, file, and dropdown components.
First, we have to create a subtheme of drulma.
Next, we override the drulma libraries.
Add the following lines to mydrulmasubtheme.info.yml:
libraries-override:
# drulma
drulma/global: false
drulma/drulmajs: mydrulmasubtheme/drulmajs
drulma/bulmajs: mydrulmasubtheme/bulmajs
drulma/bulma: false
Next, mydrulmasubtheme.libraries.yml:
global:
css:
theme:
css/style.min.css: {}
bulmajs:
js:
js/bulma.min.js: {} # only includes dropdown, file, navbar
drulmajs:
js:
js/drulma.min.js: {}
dependencies:
- mydrulmasubtheme/bulmajs
- core/drupal
The js files are the three components used by Drumla. Ideally, they would be combined into a single file as described in the bulmajs documentation, but I don't know how to do that yet. (VizuaaLOG/BulmaJS#100)
Next, I installed bulma with npm. You will need to install npm
somehow; I won't document it here.
You can use the package.json
below as an example.
Next make a style.scss file and put it in mydrulmasubtheme/sass/bulma_sass.
It could look like this:
@charset "utf-8";
// @import "node_modules/bulma/bulma.sass";
// import components individually
// TODO: eliminate unneeded components
@import "bulma_sass/utilities/_all";
@import "bulma_sass/base/_all";
@import "bulma_sass/elements/_all";
@import "bulma_sass/form/_all";
@import "bulma_sass/components/_all";
@import "bulma_sass/grid/_all";
@import "bulma_sass/layout/_all";
@import "../../contrib/drulma/css/bulma-overrides";
@import "../../contrib/drulma/css/drupal-overrides";
@import "../../contrib/drulma/css/tweaks";
To get this to work, you need to symlink the bulma sass directory installed by node (ln -s ../node_modules/bulma/sass/ bulma_sass
) or adjust the path accordingly.
Then you can compile with Gulp.
An example gulpfile is included below. This gulpfile was modified from the one provided with the Bootstrap SASS theme. To use the gulpfile, you will need to create an src
directory in your drulma subtheme and then symlink the drulma_js (ln -s ../../../conrib/drulma/js drulma_js
).
This gulpfile uses UnCSS, which automatically removes CSS that is not used on the site. This makes the stylesheet very small but it means you have to have a style guide on your site; otherwise, all the CSS will be stripped. You should configure uncss to go to at least one page of each content type, etc. on your website.
You can also use the Simple Styleguide module to easily generate a basic style guide for your site.