Sunday, May 13, 2018

I recently stumbled across the Bulma CSS framework. I'd never heard of it before, but it's been out now for over two years, and is generated considered as a pure CSS (no JavaScript) alternative to Bootstrap.

After looking at the documentation, I decided I wanted to try styling my Angular 5.x vadacl demo app with Bulma, and that I wanted to be able to take advantage of the fact that it could be customized via Sass (even though I've never worked with Sass before).

After some missteps and some research, I discovered that integrating Bulma with the Angular CLI is pretty easy. Here's what I ended up doing:

In my vadacl demo project, I ran the CLI command that updates the CLI configuration to use SCSS ("SCSS" is the latest syntax for Sass) files to generate the styles for the project: "ng set defaults.styleExt scss".

When creating a new Angular CLI project, you can use the flag "--style=scss" on the "ng new" command to do the same thing.

I then installed Bulma using npm: "npm install bulma --save-dev".

Next, I created a "sass" folder in the assets folder of my project and created a "variables.scss" file. In that file, I added the line:

$primary: #694979;

...to change the color value of the $primary Sass variable used in Bulma.

Then I created the "styles.scss" file in the src folder of my project, and in that file I added the following lines:

Initially it seemed counterintuitive that I would set my own values for the Bulma variables ahead of the import for Bulma, but Bulma is designed to accept those variable values if they've already been declared, and otherwise fall back to using the Bulma defaults.

Then I opened the "angular-cli.json" file in my project and made sure the "styles" property array included "styles.scss".

That's all I needed to do. I confirmed that everything worked by adding a few buttons to the home view of my app with Bulma styles: