Closed iatek closed 3 years ago
@iatek Following the docs for v5 exactly I'm trying to add a cursor utility. I have _functions.scss, _variables.scss, and _utilities.scss loaded first and then I have this (as per the docs):
@import "bootstrap/scss/functions";
@import "bootstrap/scss/variables";
@import "bootstrap/scss/utilities";
$utilities: map-merge(
$utilities,
(
"cursor": (
property: cursor,
class: cursor
responsive: true,
values: auto pointer grab,
)
)
);
I'm then adding this class to my element:
<a href="#" class="cursor-grab">Grab this</a>
However, the cursor-grab class I'm trying to add is nowhere to be found in the CSS output. Any idea what I'm doing wrong?
The docs don't currently show all the needed imports. But in your case, the class: cursor
is missing the trailing comma as mentioned in #32542 which will be fixed beta 2.
@iatek Sorry, I actually fixed that in my code...I noticed it was wrong in the docs. But that's not the issue. The issue is that I don't want to have to import the entire bootstrap.scss file. I'm currently doing it parts like this (for optimial load time):
// Required
@import "../node_modules/bootstrap/scss/functions";
@import "../node_modules/bootstrap/scss/variables";
@import "../node_modules/bootstrap/scss/mixins";
@import "../node_modules/bootstrap/scss/utilities";
$utilities: map-merge(
$utilities,
(
"cursor": (
property: cursor,
class: cursor,
state: hover,
responsive: true,
values: auto pointer grab,
)
)
);
// Optional
@import "../node_modules/bootstrap/scss/alert";
@import "../node_modules/bootstrap/scss/badge";
@import "../node_modules/bootstrap/scss/breadcrumb";
@import "../node_modules/bootstrap/scss/button-group";
@import "../node_modules/bootstrap/scss/buttons";
@import "../node_modules/bootstrap/scss/card";
@import "../node_modules/bootstrap/scss/carousel";
@import "../node_modules/bootstrap/scss/close";
@import "../node_modules/bootstrap/scss/containers";
@import "../node_modules/bootstrap/scss/dropdown";
@import "../node_modules/bootstrap/scss/forms";
@import "../node_modules/bootstrap/scss/grid";
@import "../node_modules/bootstrap/scss/helpers";
@import "../node_modules/bootstrap/scss/images";
@import "../node_modules/bootstrap/scss/list-group";
@import "../node_modules/bootstrap/scss/modal";
@import "../node_modules/bootstrap/scss/nav";
@import "../node_modules/bootstrap/scss/navbar";
@import "../node_modules/bootstrap/scss/pagination";
@import "../node_modules/bootstrap/scss/popover";
@import "../node_modules/bootstrap/scss/progress";
@import "../node_modules/bootstrap/scss/reboot";
@import "../node_modules/bootstrap/scss/root";
@import "../node_modules/bootstrap/scss/spinners";
@import "../node_modules/bootstrap/scss/tables";
@import "../node_modules/bootstrap/scss/toasts";
@import "../node_modules/bootstrap/scss/tooltip";
@import "../node_modules/bootstrap/scss/transitions";
@import "../node_modules/bootstrap/scss/type";
@import "../node_modules/bootstrap/scss/bootstrap-grid";
@import "../node_modules/bootstrap/scss/bootstrap-reboot";
@import "../node_modules/bootstrap/scss/bootstrap-utilities";
// Helpers
@import "../node_modules/bootstrap/scss/helpers";
// Utilities
@import "../node_modules/bootstrap/scss/utilities/api";
Shouldn't this work? (I can confirm it currently does not) I can't imagine that the only way to add custom utilities is to be forced to always load the entire bootstrap.scss file...
It does work as I mentioned here: https://stackoverflow.com/a/65386748/171456 .. but why import all those files separately after the changes? .. just import bootstrap entirely.
Importing the entire bootstrap scss file is not optimal for load time in a production environment. When my project is deployed to production, I plan to remove all the imports that I don't need. Bootstrap docs even recommend this: "When using Sass in your asset pipeline, make sure you optimize Bootstrap by only @importing the components you need."
I shouldn't have to import the entire bootstrap.scss file for this to work right?
Are you using all of Bootstrap? .. or just the Bootstrap utilities?
I'm using various parts of bootstrap, but just for example, there's several parts like modals, breadcrumbs, etc. I won't need and plan to remove from the imports.
Then you would @import those other parts after the changes, and yes would work as long as you @import utilities after
See my code above, I am making all my imports after the changes, except for:
@import "../node_modules/bootstrap/scss/functions";
@import "../node_modules/bootstrap/scss/variables";
@import "../node_modules/bootstrap/scss/utilities";
...which are being imported before.
And this still does not work.
For me it seems to work: https://codeply.com/p/m14Nzv3jVX
Make sure the paths are all correct and the SASS compiler has the correct includePaths
. Also, is bootstrap.css being referenced/included outside of your SASS customization?
My paths are correct and the output css file is being referenced correcty. If I remove all the parts except bootstrap-utlities like you have in your exmaple, then yes, cursor grab works.
But if I include all the other parts after (like in my example a few comments back), then 'cursor-grab' does not get compiled in my css file...
The only way I can now get it to work is if I move @import "../node_modules/bootstrap/scss/bootstrap-grid";
above the custom code with the others like this:
// Required
@import "../node_modules/bootstrap/scss/functions";
@import "../node_modules/bootstrap/scss/variables";
@import "../node_modules/bootstrap/scss/utilities";
@import "../node_modules/bootstrap/scss/bootstrap-grid";
That doesn't seem right...Why would bootstrap-grid need to be imported first in order to add a utility class?
@adro21 because if you just want to optionally add the grid classes you should only @import "../node_modules/bootstrap/scss/grid"
. bootstrap-grid
is for building a grid/flexbox only version, and therefore also imports utilities which is resetting your utility overrides. It's all explained in the customize docs
It works: https://codeply.com/p/m14Nzv3jVX
Anyway, @XhmikosR I didn't intend for this issue to be hijacked with SASS debugging. If you think my aforementioned feature request (to mention the other required @imports) is legit I'd be happy to open a PR.
@iatek Sorry, didn't mean to hijack the thread! Appreciate your help and the explanation, but anyway, your example still isn't working for me: https://d.pr/v/harXWd
Utility API docs: Add
@import
functions, variables to the examples.Since
_utilities
references,_variables
, and_variables
references_functions
, in order to use the API you must import like..Should this be mention in the Using the API section, perhaps explain in the text that says "Make sure our _utilities.scss is imported first,"? Or, simply add the correct
@imports
in each of the examples?