I'm developing an application with React using Bootstrap 4 with Sass and webpack for building, every React component has it's own .scss file.
I've run into a problem, where I need to use Bootstrap's variables, but I can't import bootstrap because I end up with Bootstrap imported multiple times (apart from performance issues duplicate imports keep overriding my changes to Bootstrap's rules)
My main two problems are:
ComponentAstylesheet has to access Bootstrap's variables and mixins (i.e.button-variant), to achieve that I have to@importBootstrap inside my.scssfile (otherwise I end up gettingundefined variableerrors).- Adding
@import '~bootstrap'to every component's stylesheet results in importing whole Bootstrap multiple times. So when I override a variable, i.e.$body-bgin myglobal.scssfile, which contains shared styles, it only uses my value in first import, what means that every succeeding Bootstrap import doesn't get my variables, and keeps overriding it with defaults.
Are there any methods for dealing with that kind of problems? My guess would be to somehow enable "global scope", so I can use variables/mixins without continously importing whole Bootstrap.
Edit: I've found a workaround, when Sass files are imported from other Sass file, the variables are accessible, so creating a single big import.scss file instead of using separate imports from .js files seems to work.