I am using create-react-app (without ejection) for one of my application, and have the following folder structure:
/src
assets
scss
abstract
_variables.scss
_mixins.scss
_global.scss
components
Welcome
Welcome.js
Welcome.scss
App.js
App.scss
The contents of the files are below:
_variables.scss
$color-info: #f45a40;
global.scss
@import "./abstract/variables";
@import "./abstract/mixins";
App.scss
@import "assets/scss/global";
App.js
import React from "react";
import "./App.scss"
import Welcome from "./components/Welcome"
const App = () => {
return (
<Welcome />
);
};
export default App;
Welcome.js
import React from "react";
import "./Welcome.scss"
const Welcome = () => {
return (
<div class="text-color">Some test here</div>
);
};
export default Welcome;
Welcome.scss
.text-color {
color: $color-info;
}
Since i am already including the "global.scss" in "App.scss", should it not automatically make all partials available for components like "Welcome.js"? Unfortunately its not, its throwing me the following error in "Welcome.scss" file:
SassError: Undefined variable: "$color-info".
But, if I include 'global.scss' in the "Welcome.scss" file, then it works fine. I do not want to include global.scss in each and every component, is there a way to make this work?