I created a basic React application using CRA and react-bootstrap. I would like to load different bootswatch themes. All themes are downloaded and placed inside a src/themes
folder. Each theme has its own folder with fixed set of filenames:
src/themes/
superhero/
_bootswatch.scss
_variables.scss
bootstrap.css
bootstrap.min.css
/cerulean
_bootswatch.scss
_variables.scss
bootstrap.css
bootstrap.min.css
and so on...
Now suppose I want to load superhero theme. This can be done in different ways which I show below:
I renamed
index.css
of CRA toindex.scss
and added the following lines to the top of the file (I have node-sass installed):@import "./themes/superhero/variables"; @import "~bootstrap/scss/bootstrap"; @import "./themes/superhero/bootswatch";
I add the following line to index.js:
import './themes/superhero/bootstrap.min.css'
Both of these methods are working fine independently. What I want to do is to import them in index.js like this:
import './themes/superhero/_variables.scss'
import 'bootstrap/scss/bootstrap.scss';
import './themes/superhero/_bootswatch.scss'
When I do this, the first two lines get imported properly but I receive undefined variable errors when it comes to the third import, _bootswatch.scss
. This is because the first two files are independent. I think there are dependent variables in the third file but on each import they are somehow scoped differently and hence the last import does not have access to the variables. This is not the case for method 1, they are all imported to a single file and then node-sass takes care of them.
Any ideas how to solve the issue?