I want to add .scss
support in my app, which was created using create-react-app.
I did eject npm run eject
and installed necessary dependencies: npm install sass-loader node-sass --save-dev
Inside config/webpack.config.dev.js
I added to the loaders this snippet:
{
test: /\.scss$/,
include: paths.appSrc,
loaders: ["style", "css", "scss"]
},
So the beginning of the loaders array now look like so:
loaders: [
// Process JS with Babel.
{
test: /\.(js|jsx)$/,
include: paths.appSrc,
loader: 'babel',
query: require('./babel.dev')
},
// "postcss" loader applies autoprefixer to our CSS.
// "css" loader resolves paths in CSS and adds assets as dependencies.
// "style" loader turns CSS into JS modules that inject <style> tags.
// In production, we use a plugin to extract that CSS to a file, but
// in development "style" loader enables hot editing of CSS.
{
test: /\.css$/,
loader: 'style!css!postcss'
},
// LOAD & COMPILE SCSS
{
test: /\.scss$/,
include: paths.appSrc,
loaders: ["style", "css", "scss"]
},
Now in my jsx when I try to import scss file:
import './assets/app.scss';
I get an error:
Uncaught Error: Cannot find module "./assets/app.scss"
So my config must be wrong as I'm not able to load .scss
files. How to adjust config to load .scss
files in ejected create-react-app
?
as per Latest Configuration [CRA]
::webpack.config.dev.js::
OK, I found the solution - changed from this:
to this:
And now my
.scss
files are loading!!You probably have to use
option to enable webpack hot-reload. So you config snippet could looks like
When trying to integrate sass into empty react project I used this article. The solution presented there did not work and received the similar error as in the subject. In my case replacing
style-loader
withrequire.resolve('style-loader')
helped:Check this loader settings for the latest versions.
Check the first loader, first it get all the files and it excludes the other loaders files
so adding
to exclude, seems that fixed the same problem I had :D