create-react-app中依赖的react-scripts中webpack没有对sass和less做配置,所以使用时要我们自己来配置。

1、执行 yarn eject        --弹出配置文件(注意:这个操作是不可逆的)

2、执行 yarn add node-sass sass-loader   --安装sass依赖

3、在config文件中找到webpack-config-dev.js和webpack-config-prod.js文件

4、两个文件中同样都加上红色方框中的内容;

create-react-app与sass

代码如下:

{
    test: /\.scss$/,
    loaders: ['style-loader', 'css-loader', 'sass-loader'],
},
exclude: [/\.(js|jsx|mjs)$/, /\.html$/, /\.json$/, /\.scss$/],

5、配置完成

相关文章:

  • 2022-12-23
  • 2021-12-31
  • 2022-12-23
  • 2022-12-23
  • 2021-08-13
  • 2022-12-23
  • 2021-07-26
  • 2022-12-23
猜你喜欢
  • 2021-12-20
  • 2021-12-09
  • 2022-12-23
  • 2022-12-23
  • 2021-09-22
  • 2022-12-23
相关资源
相似解决方案