How to use absolute path to import custom scss, when using react + webpack?
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")]
}
Absolute import using Webpack resolve.alias in a React app
as Prakash pointed out above, here's what I needed to do:
resolve: {
alias: {
components: path.resolve(__dirname, 'src/components'),
reducers: path.resolve(__dirname, 'src/reducers')
},
extensions: ['.js']
},
Import react components with absolute path
My file structure follows exactly the same pattern as yours. To teach Jest into using imports beginning with a /
, I use babel-plugin-module-resolver and its handy root
option. My .babelrc
for Jest looks like this:
{
"presets": ["es2015", "meteor"],
"plugins": [
"transform-class-properties",
"transform-react-constant-elements",
"transform-react-inline-elements",
"transform-react-remove-prop-types",
["module-resolver", {
"root": ["../"],
"alias": {
"react-router-dom": "react-router-dom/umd/react-router-dom.min.js",
"redux": "redux/dist/redux.min.js",
"react-redux": "react-redux/dist/react-redux.min.js"
}
}]
]
}
As I'm using Meteor which customized its root imports, I hide my Jest usage and configuration into a .jest
directory at the root of my repository allowing me to have a specific .babelrc
without risking conflicts with Meteor's one.
Related Topics
How to Increase Bootstrap 3 Navbar Height While Keeping Menu Height Small When Collapsed
Reactjs How to Use Ref Inside Map Function
How to Make The Body Width Equal to The Device-Width Automatically in CSS3 Media Query
How to Make My <Input Type="Submit" /> an Image
Gulp-Sass Fails to Compile SCSS File
Reverse Svg Line Drawing Animation
Font Awesome Animated Spinner Through Background
Bootstrap 4: How to Have a Full Width Navbar with The Content in a Container (Like The So Navbar)
Update Source File When CSS Is Changed Through Chrome Developer Tools
Using Container-Fluid Within Bootstrap Cause Horizontal Scrollbar
How to Greyout a Disabled Field
CSS: Inline Element Stretch to Fill Available Horizontal Space of Container
Vertical Alignment Based on X-Height
Strange Z-Index Behavior with Scrollbars Under Chrome
CSS Animate Text from Left to Right in Div Container with Overflow Hidden