#一、安装依赖
cnpm install sass-loader node-sass --save-dev (npm可能出错)
#二、配置文件
1.打开node_modules/react-scripts/config/webpack.config.dev.js
在model 的rules中找到oneof插入
{
test:/\.scss$/,
loaders:['style-loader','css-loader','sass-loader']
}
2.在exclude中添加/.scss$/
{
loader: require.resolve('file-loader'),
// Exclude `js` files to keep "css" loader working as it injects
// its runtime that would otherwise be processed through "file" loader.
// Also exclude `html` and `json` extensions so they get processed
// by webpacks internal loaders.
exclude: [/\.(js|mjs|jsx|ts|tsx)$/, /\.html$/, /\.json$/,/\.scss$/],
options: {
name: 'static/media/[name].[hash:8].[ext]',
},
},
#三、把.css文件改成后缀为.scss的文件