richjdsmith

richjdsmith

Brunch Config Instructions for Bulma

Anyone willing to explain to me how to include the Bulma CSS Framework with Brunch? I haven’t warped my head around brunch yet. Here’s what I have done so far.

  1. Installed sass-brunch
    $ cd assets && npm install --save sass-brunch

  2. Installed bulma
    $ npm install --save bulma

  3. Removed bootstrap
    $ echo "" > css/phoenix.css

  4. Added sass-brunch to my Brunch Config (I think this is where I went wrong)
    Gist to brunch-config (how do I embed?)

Summary
exports.config = {
  // See http://brunch.io/#documentation for docs.
  files: {
    javascripts: {
      joinTo: "js/app.js"

      // To use a separate vendor.js bundle, specify two files path
      // http://brunch.io/docs/config#-files-
      // joinTo: {
      //   "js/app.js": /^js/,
      //   "js/vendor.js": /^(?!js)/
      // }
      //
      // To change the order of concatenation of files, explicitly mention here
      // order: {
      //   before: [
      //     "vendor/js/jquery-2.1.1.js",
      //     "vendor/js/bootstrap.min.js"
      //   ]
      // }
    },
    stylesheets: {
      joinTo: "css/app.css"
    },
    templates: {
      joinTo: "js/app.js"
    }
  },

  conventions: {
    // This option sets where we should place non-css and non-js assets in.
    // By default, we set this to "/assets/static". Files in this directory
    // will be copied to `paths.public`, which is "priv/static" by default.
    assets: /^(static)/
  },

  // Phoenix paths configuration
  paths: {
    // Dependencies and current project directories to watch
    watched: ["static", "css", "scss", "js", "vendor"],
    // Where to compile files to
    public: "../priv/static"
  },

  // Configure your plugins
  plugins: {
    babel: {
      // Do not use ES6 compiler in vendor code
      ignore: [/vendor/]
    },
    sass: {
      includePaths: ['node_modules/bulma/']
    }
  },

  modules: {
    autoRequire: {
      "js/app.js": ["js/app"]
    }
  },

  npm: {
    enabled: true
  }
};
  1. Renamed app.css to app.scss
    $ cd assets/css; mv app.css app.scss

  2. Imported Bulma into my app.scss
    @import "bulma";

  3. Added a folder for my scss files
    $ mkdir assets/scss $ touch assets/scss/custom.scss

  4. Just added some dummy code to my new custom.scss
    @import "../node_modules/bulma/sass/utilities/initial-variables"; $primary: $red

  5. Added my custom css to app.scss below the import for bulma.
    @import "../scss/custom";

I did all this following instructions from @kaputse (whom it appears is on here! :D)

Unfortunately, doing all this, compiling of css/app.scss failed :frowning:

[debug] Processing with LaterReviewWeb.PageController.index/2
  Parameters: %{}
  Pipelines: [:browser]
[info] Sent 200 in 352µs
18:08:27 - info: Reloading watcher...
(node:33658) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 SIGTERM listeners added. Use emitter.setMaxListeners() to increase limit
18:08:29 - error: Compiling of css/app.scss failed. L2:1:
   File to import not found or unreadable: bulma
   Parent style sheet: /Users/richsmith/later_review/assets/css/app.scss Error: File to import not found or unreadable: bulma
          Parent style sheet: /Users/richsmith/later_review/assets/css/app.scss

   >> @import "bulma";
      ^
Stack trace was suppressed. Run with `LOGGY_STACKS=1` to see the trace.
[debug] Live reload: priv/static/js/app.js
[debug] Live reload: priv/static/js/app.js 

Any help or suggestions would be appreciated and hopefully this can solve the issue for others. Cheers!

Most Liked

EssenceOfChaos

EssenceOfChaos

Here is a simpler set up for using different front-end frameworks.

Also, it looks like you are copy/pasting from a project that was made prior to phoenix 1.3 (there is no longer a “web” folder in the root directory). I have a video tutorial on how to get started with Phoenix and I chose to use Bulma as the css framework, check it out here. If you like it please give it a thumbs up!

To use Sass with Phoenix, install the “sass-brunch” plugin as a dev-dependency. Leave the file concatenation as is and rename the assets/css folder to scss. This way you can also rename app.css to app.scss and the only thing you have to change in the brunch.config is the one path under “watched:” from “css” to “scss”.

As mentioned, add the sass plugin to the plugins section of brunch config, specifying any paths that should be included. This would be like

sass: {
            options: {
                includePaths: [
                    "node_modules/bootstrap/scss",
                    "node_modules/font-awesome/fonts"
                ]
            }

This works for bootstrap, foundation, and other frameworks that use scss.

With this setup, you can create as many stylesheets as needed, prepend them with underscores ( _ ) as in, _variables.scss and @import them into your main stylesheet app.scss.

Hope this helps someone!

dwyd

dwyd

The following configuration worked for me when I added Bulma to a Phoenix 1.3 project… your npm steps look correct at a glance. Make sure sass and bulma are in node_modules.

package.json should have something similar after NPM install

# ./assets/package.json
{
...
  "dependencies": {
...
    "bulma": "^0.5.0",
...
  },
  "devDependencies": {
...
    "sass-brunch": "^2.10.4",
...
  }
}

Update brunch-config.js

# ./assets/brunch-config.js
exports.config = {
  files: {
    stylesheets: {
...
      joinTo: "css/app.css",
      order: {
        after: [ "css/app.scss"]
      }
    },
...
  },

...

  // Configure your plugins
  plugins: {
...
    sass: {
      mode: 'native',
      options: {
        includePaths: ['node_modules/bulma']
      }
    }
  },
...
};

Add app.scss to ./assets/css/

# ./assets/css/app.scss
@import "bulma";

You can do all your overrides in app.scss

Compile the app

iex -S mix phx.server

cmkarlsson

cmkarlsson

I just set bulma + phoenix 1.3 up a couple of days ago and I followed this gist:

But replaced bootstrap with bulma.

With the exception that my app.scss looks like this:

@import "node_modules/bulma/bulma";

and my brunch config sass option looks like this:

  plugins: {
    babel: {
      // Do not use ES6 compiler in vendor code
      ignore: [/vendor/]
    },
    sass: {
        options: {
            includePaths: ["node_modules/bulma/sass"],
            precision: 8
        }
    }
  },

Where Next?

Popular in Questions Top

Kurisu
For example for a current url like http://localhost:4000/cosmetic/products?_utf8=✓&query=perfume&page=2, I would like to get: ...
New
shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New

Other popular topics Top

lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 39297 209
New
AstonJ
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including. What is Phoenix LiveV...
New
klo
Got a question about when to concat vs. prepending items to list then reversing to achieve appending. So i know lists boil down to [1 | ...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New

We're in Beta

About us Mission Statement