After installing bulma through NPM, how can I refer it in my project
Asked Answered
L

7

60

I have pulled in bulma in my project through :

$ npm install bulma

After that, how can I refer to it in my pages. I really don't know how to work with npm, so please can you guide me. Do I have to refer to it in my js by saying: import bulma from 'bulma' or require it, I don't know where my files are. That means I don't know where are they located.

Leisurely answered 17/5, 2017 at 7:18 Comment(0)
S
65

You can find the final css build at projectName/node_modules/bulma/css/bulma.css.

Chances are you're using a file loader with webpack and similar. If, for example in a Vue project, you have that, then you can use import syntax:

import 'bulma/css/bulma.css'

within your js. This works because having import [xyz from] 'xyz' will look at projectName/node_modules/xyz, and in the case of a css file, it's as simple as that!

If you do not have that installed, you need to find a way to send it over to the client. Just copy projectName/node_modules/bulma/css/bulma.css into a file, maybe bulma.css, in either an assets or public or whatever you use, then fetch it like you'd fetch any css file within the html: <link rel="stylesheet" href="/bulma.css">

Shaky answered 24/6, 2017 at 12:1 Comment(1)
In Vue.js as an example, I can just use import Bulma from 'bulma' in main.js and it works.Ctenidium
E
7

@import "../node_modules/bulma/css/bulma.css";

If you have a main.css file for your project or something similar to that, you can add the above line inside your main.css file. This will import the default bulma.css file located inside your project's path node_modules/bulma/css/ after you have installed bulma via npm.

NOTE: you must include your main.css file( or something similar) inside your index.html as a static import if you chose to go this way. For that you need to have something like:

<link rel="stylesheet" href="/css/main.css">

I prefer this since bulma is a CSS framework, I think it's best to keep the stylesheets linked with each other.

Error answered 12/8, 2018 at 3:59 Comment(1)
This works great in Visual Studio Code when you also enable the extension "Live Server" to run at the same time. No need to install and configure Webpack for something thats not robust, especially if you simply want a do a crash course with Bulma alone. Thanks.Incardinate
N
5

It's CSS only.

Bulma is a CSS framework.

So you can add it just in your index.html like a normal css link:

<link rel="stylesheet" type="text/css" href="your/bulma/path/bulma.css />

Edit: You have installed bulma through the nodejs environment with the package manager npm so you must have a directory called node_modules and inside the bulma directory.

Novocaine answered 17/5, 2017 at 7:40 Comment(5)
What if I'm using it in a back-end framework. What is the bulma path for it ?Leisurely
@d3cypher I edited the answer although I don't understand what you mean with the back-end framework since this has to do with the client side, it's css. Hope I helped you!Novocaine
@d3cypher Was my answer useful? you found it?Novocaine
As he mentioned, you can add the link in your static index fileRayford
Is this practice used in production level as well or is it just for development purpose?Error
P
2

That is really unevident. If you want to get bulma work with fontawesome5 via npm, minimum working deps (for now) are:

npm i -S bulma @fortawesome/fontawesome @fortawesome/fontawesome-free-solid

then needed to be initialized like this:

import fontawesome from '@fortawesome/fontawesome'
import solid from '@fortawesome/fontawesome-free-solid'
import 'bulma/css/bulma.css'

fontawesome.library.add(solid)

More details can be found here: https://fontawesome.com/how-to-use/use-with-node-js

Prate answered 12/4, 2018 at 12:13 Comment(0)
F
2

I had the same issue in Vue and in the end I solved it thanks to this link. For Bulma you just need to run:

$ npm install bulma

After npm install, your files should be located under node_modules folder.

For Bulma, check that you have a folder bulma under node_modules, then you can import bulma css framework in your main.js file as follows: import "./../node_modules/bulma/css/bulma.css";

Note: even if on the link I provided they suggest the full path to bulma this is not a good practice as @Omkar pointed out, so I ended up importing bulma as follows: import "bulma/css/bulma.css";

Flossieflossy answered 2/5, 2018 at 17:17 Comment(3)
do not suggest beginners to use ../../ relative paths. Using webpack, you can use aliasesBetwixt
Do you mean using @/../node_modules/... I can edit my answer if this is what you suggestFlossieflossy
No, look at relative paths vs aliases. Node js automatically picks up node modules, so you dont have to provide a complete path. Either ways, even if its not from node modules, its recommended to use aliases provided by module bundlers to reduce the nesting of paths. The practice of nesting will end up adding lot of unreadable paths when the app will grow large.Betwixt
N
1

Alternative Answer: CSS Preprocessing

I'm posting a somewhat indirect way to answer the question. I came here looking to see how I could use rendered SASS in my main app.js (in my case, for use in a pug.js template).

The answer is: use a CSS pre-processor. In this minimal example, I'll use node-sass.

0. Install:

npm install node-sass
npm install bulma

1. Create an inherited style

mystyles.scss:

@charset "utf-8";
@import "node_modules/bulma/bulma.sass"; // <--- Check and make sure this file is here after installing Bulma

This will inherit styles from the Bulma installation, but override those styles with what you place here.

2. Build the CSS

app.js:

const nsass = require("node-sass");

const rendered_style = nsass.renderSync({ // <---- This call is synchronous!
  file: "./mystyles.scss",
});

Here, node-sass is processing the .scss file into a Result object that has CSS buffer. Note that node-sass has an asynchronous call (sass.render()) as well, if needed.

3. Use the CSS

The buffer containing the CSS is now available at rendered_style.css

console.write(rendered_style.css)

--Notes--

The benefit of the SASS approach is that it unlocks Customization, which is what makes Bulma powerful!

Keep in mind that if app.js is your entry point, the CSS will be rendered every time you run the server. If your styles aren't changing frequently, it may be best to write it out to a file. You can see more on this approach in the Bulma Documenation I adapted this from.

Nealneala answered 7/8, 2020 at 6:21 Comment(0)
F
-3

declaring this in the index.html file worked for me.

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.6.0/css/bulma.min.css">

In React, we have to declare this in the same html file where the root of the app is present.

Furring answered 25/10, 2017 at 19:32 Comment(1)
If the OP has installed already using npm. He probably does not want to pull in Bulma using CDN.Giffard

© 2022 - 2024 — McMap. All rights reserved.