8

I'm trying use scss in a kotlin-react application using create-react-kotlin-app in node for easy bootstrapping, but I'm stuck with setting the configuration to make it work

I already ejected, so I can manually edit the webpack config. I already added the following to dev config and the corresponding equivalent to prod.

  {
    test: /\.scss$/,
    use: [
      require.resolve('style-loader'),
      {
        loader: require.resolve('sass-loader'),
        options: {
          importLoaders: 1,
        },
      },
      {
        loader: require.resolve('postcss-loader'),
        options: {
          ident: 'postcss', // https://webpack.js.org/guides/migrating/#complex-options
          plugins: () => [
            require('postcss-flexbugs-fixes'),
            autoprefixer({
              browsers: [
                '>1%',
                'last 4 versions',
                'Firefox ESR',
                'not ie < 9', // React doesn't support IE8 anyway
              ],
              flexbox: 'no-2009',
            }),
          ],
        },
      },
    ],
  },

modified package.json with and run npm install

"babel": {
 "presets": [
   "react-app"
 ],
 "plugins": [
   [
     "babel-plugin-react-css-modules",
     {
       "filetypes": {
         ".scss": {
           "syntax": "postcss-scss"
         }
       }
     }
   ]
 ]
}

and also added to index.kt

requireAll(require.context("src", true, js("/\\.scss$/")))

the latest config of create-react-app in node already supports scss, so I follow this tutorial https://medium.com/front-end-weekly/how-to-add-sass-or-scss-to-create-react-app-c303dae4b5bc since the ejected result of webpack config in the create-react-kotlin app is almost the same, but still got no luck.

0 Answers0