一、安装

  • 1、安装loader

    install sass-loader node-sass --save-dev

二、配置

  • 1、找到node_modules/react-scripts/config/webpack.config.dev.js文件和webpack.config.prod.js
  • 2、新增圈住的地方
    creact-react-app创建react项目配置scss_react
{
    loader: require.resolve('file-loader'),
    // Exclude `js` files to keep "css" loader working as it injects
    // it's runtime that would otherwise processed through "file" loader.
    // Also exclude `html` and `json` extensions so they get processed
    // by webpacks internal loaders.
    exclude: [/\.js$/, /\.html$/, /\.json$/,/\.scss$/],
    options: {
        name: 'static/media/[name].[hash:8].[ext]',
    },
},
{
    test: /\.scss$/,
    loaders: ['style-loader', 'css-loader', 'sass-loader'],
}