css - React with SASS - 如何在 React 中使用 SASS

标签 css reactjs sass

那么,SASS在react中的基本用法是

安装node-sass并在index.js文件中导入./mysass.scss

我做了同样的事情,它与 bootstrap SASS 一起工作。

我已成功在 index.js 文件中导入 bootstrap.scss

import 'bootstrap/scss/bootstrap.scss';

但是,现在如果我尝试导入我的,它不起作用。

让我向您提供一些有关我的 SASS 文件的信息。

  • 我的 style.scss 文件在 sass 中使用 @use 而不是 @import 导入其他 CSS 模块。

    例如

      Using -> `@use 'sections/navbar';`
      Instead of  -> `@import 'sections/navbar';`
    
  • 我也在使用@use "sass:map";

这个@use会产生问题吗?

我已经检查了 bootstrap.scss 文件,它们正在使用 @import

最佳答案

在 Github 上查看此问题:Link 。用户asyncLiz发布的解决方案。

That error is typically seen when using the node-sass implementation, which does not support Sass modules and is not supported by MDC. You'll need to use the Dart sass implementation.

Luckily it's an easy replacement when using sass-loader. Run npm uninstall node-sass && npm install sass. sass-loader will automatically use the new implementation.

If it does not, check your webpack.config.js in case you're manually specifying the implementation in your sass-loader options. If you are, change implementation: require('node-sass') to implementation: require('sass').

关于css - React with SASS - 如何在 React 中使用 SASS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68438682/

相关文章:

css - 如何在 SVG 中制作插入阴影

css - 图像的自动标题不起作用 : img[title]:after{content:attr(title);}

css - 引用父值

css - 如何在css中将圆圈的一部分设置为背景

css - 如何在当前目录中为单个文件编译 node-sass

html - 在底部制作一个div内容到 "bleed"(或者阻止背景图片渲染)

CSS 3D 轮播元素不尊重 TranslateZ

javascript - React-Native FlatList 不使用自定义 renderItem 重新渲染

javascript - 如何改变滚动时的背景颜色?

reactjs - 错误 TS2307 : Cannot find module 'react'