Rework Bootstrap import order #1792
Merged
+143
−86
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Previously, we were importing parts of Bootstrap multiple times. In short, this aims to fix that.
https://getbootstrap.com/docs/5.3/customize/sass/#importing details the basic structure, but is significantly less useful than looking at the .scss files Bootstrap comes with.
The general idea is that Bootstrap can be imported in one of two ways; option 1 is to just import the entirety of Bootstrap as is, which you can do via
@import "~bootstrap/scss/bootstrap";. This would be fine, but there is a problem with customisation.We have many places where we want to customise Bootstrap, e.g. by adjusting defaults, extending maps further than the default, etc. To allow you to do this, all the Bootstrap variables are defined with
!default, meaning if a definition for that variable already exists, that definition will always override the default. Therefore, by defining e.g.$border-color: {val}before importing Bootstrap, any BS variables that inherit from$border-colorwill use that value instead.However. Bootstrap also defines its own functions, and there are times we need to use these functions inside the override. Also, we may e.g. want to extend a Bootstrap map, for which a self-referential declaration like
which can make use of Bootstrap's default is much simpler than having to rewrite it.
In both of these situations, we need to import these bits from Bootstrap first, then apply our overrides, and would then need to import Bootstrap again to make use of them. This is what we were doing before (badly) and is why we have duplicate imports.
To fix this, option 2 for importing Bootstrap is piecewise. There are 5 "required" Bootstrap imports:
There are also a bunch of other optional imports, though since we were previously importing the entirety of Bootstrap, we have made use of most of these optionals somewhere in the code.
We can add overrides in between these imports; they should be after
variablesand beforeutilities, since most of our customisation is changing the raw values of these BS defaults, which we wantutilitiesto process. This idea defines the new structure of theisaac.scssfiles.To import the rest of Bootstrap, rather than
@import "~bootstrap/scss/bootstrap";as before (which duplicates the above imports), we need to import all the optional libraries individually. Unfortunately, there is no easy way to do this; I was hoping BS might come with an import for all the optionals, since there are various other files they offer you can import that cover common cases, but no luck. As such, I have createdscss/common/bootstrap-contents.scss, which is a dump of the "~bootstrap/scss/bootstrap" file without the 5 imports above. This is imported after theutilitiesimport.I have restructured most of the Bootstrap-relevant imports of both
isaac.scssfiles to be more logical and to group related bits together.