1

I want to use scss directly in my components. Now I import css like this:

import './test.css';

return (
    <Container>
      <Col sm="12">
        <div className="test_wrapper">

I want to use like this: import './test.scss';

return (
    <Container>
      <Col sm="12">
        <div className="test_wrapper">
Alessio
  • 3,404
  • 19
  • 35
  • 48
rick1
  • 946
  • 3
  • 15
  • 31

1 Answers1

0

As the comments already suggest, you need to install a webpack loader for scss.

npm i -D sass-loader

And add the rule to your webpack configuration.

{
  test: /\.scss$/,
  use: [ 'css-loader', 'sass-loader' ],
},

If you are using jest, you should also look into jest-css-modules, or you will run into problems.

nbkhope
  • 7,360
  • 4
  • 40
  • 58
lukas-reineke
  • 3,132
  • 2
  • 18
  • 26
  • I do not use jest – rick1 Mar 02 '18 at 16:44
  • { test: /\.scss$/, use: [{ loader: "style-loader" // creates style nodes from JS strings }, { loader: "css-loader" // translates CSS into CommonJS }, { loader: "sass-loader" // compiles Sass to CSS }] }, I have such a config in webpack.config.js bug it doesnt work – rick1 Mar 02 '18 at 16:50
  • Maybe you are missing the `style-loader`? That is the one that actually "applies" the styles. `css-loader` merely takes it in and puts in the JS file. `{ loader: "style-loader" // creates style nodes from JS strings }` Ref https://github.com/webpack-contrib/sass-loader – nbkhope Mar 02 '18 at 17:55