Inside a scss file, I'm trying to import custom, widely used chunk of scss (in a React/SASS/Webpack stack).
So that I can use a shared mixin.
Let's say I'm creating an MyAdminButton and I want to import scss file that concerns all the buttons of the project. (It's custom scss, not vendor/external one).
It would look like this :
//this actually works but it is a code smell : what if the current file moves ? @import "../../stylesheets/_common-btn-styles.scss"; .my-admin-btn { // here I can use a shared mixin defined in _common-btn-styles.scss }
This sounds not good since if my scss file move, then everything is broken.
Thanks for your help
To add SCSS styles to a React project, we can install the sass package if the React project is created with create-react-app. Then we import a SCSS file by writing: import '../scss/styles.
When initializing React Project with create-react-app, we can configure our React application to support importing modules with absolute paths. Note: We can create the jsconfig. json file if it doesn't exist. Now we have the working absolute imports setting with src folder as custom base directory.
Found. Actually you can configure sass-loader in webpack.config.json, as described here : https://github.com/jtangelder/sass-loader
Here is the relevant part :
sassLoader: { includePaths: [path.resolve(__dirname, "./some-folder")] }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With