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.
Installed sass-brunch $ cd assets && npm install --save sass-brunch
Installed bulma $ npm install --save bulma
Removed bootstrap $ echo "" > css/phoenix.css
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
}
};
Renamed app.css to app.scss $ cd assets/css; mv app.css app.scss
Imported Bulma into my app.scss @import "bulma";
Added a folder for my scss files $ mkdir assets/scss $ touch assets/scss/custom.scss
Just added some dummy code to my new custom.scss @import "../node_modules/bulma/sass/utilities/initial-variables"; $primary: $red
Added my custom css to app.scss below the import for bulma. @import "../scss/custom";
Unfortunately, doing all this, compiling of css/app.scss failed
[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!
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
I remember running into similar issues. Maybe try the following (in no particular order)?
# clean up stale files
cd assets/
rm ./package-lock.json
rm -r ./node_modules
npm cache clear --force
npm install
./node_modules/brunch/bin/brunch build
# rebuild sass if needed
# warn: Loading of sass-brunch failed due to Node Sass does not yet support your current environment: Linux 64-bit with Unsupported runtime (57)
cd assets/
npm rebuild node-sass
npm install
./node_modules/brunch/bin/brunch build
Fortunately, it seems to be compiling as far as I can tell anyhow. But the brunch watching task is slow (and isn’t normally), and I am still getting this damned error. I’ve even tried running brunch-sass both in native and not.
The slow brunch compiling leads me to believe that it’s getting caught on something then continuing on. For now I suppose I will ignore it until I get frustrated enough to keep working at it.
$./node_modules/brunch/bin/brunch b 12:21:10 - info: compiled 6 files into 2 files, copied 3 in 1.8 sec 12:21:10 - error: Cannot read property 'verbose' of undefined
For the curious, here are some sass-brunch configs I’ve tried (various true/false combos etc.).
I tried the steps I layed out in the blog and it just works for me. One thing I found was that the editor messed up step 4. Thanks for the comment on that. I fixed it.
// Configure your plugins
plugins: {
babel: {
// Do not use ES6 compiler in vendor code
ignore: [/vendor/]
},
sass: {
options: {
includePaths: ["node_modules/bulma/sass"], // Tell sass-brunch where to look for files to @import
precision: 8 // Minimum precision required by bootstrap-sass
}
}
},
7.Boom. Done! Go enjoy a chocolate bar or something, you’ve now got Bulma.io running on your phoenix site!
To everyone above who helped me, thanks so much! Not sure what the heck was going on, but I just did the above steps on a new project and ran into no errors at all. Such is programming!
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
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.