reactjs - problem in accessing the scss variables in react components
问题描述
Followed the link https://mattferderer.com/use-sass-variables-in-typescript-and-javascript
Looking to access the scss varaibles in react component . Not sure with what import name i need to call in react component since if i give as below import statement it is showing an error as cannot find the module '../scss/_variables.scss';
import _variables from '../scss/_variables.scss';
here _variables.scss is the file name which contains
// variables.scss
$white-color: #fcf5ed;
:export {
whitecolor: $white-color; }
I am scratching my head to get the "whitecolor" variable available in react component .
Also, I am using webpack as below
{
test: '/.scss$/',
use: [{
loader: 'style-loader' // creates style nodes from JS strings
}, {
loader: 'css-loader' // translates CSS into CommonJS
}, {
loader: 'sass-loader' // compiles Sass to CSS
}]
}
Any help would be highly appreciated!!
解决方案
除非它是一个模块,否则在 React 中导入特定属性不起作用。
我遇到了同样的问题,这就是我所做的:
重命名_variables.scss
为_variables.module.scss
,然后导入为import _variables from '../scss/_variables.module.scss';
现在您可以像访问 scss 变量一样_variables.whitecolor
推荐阅读
- mongodb - 无法从 db_dump 恢复 MongoDB
- jekyll - 我的 Jekyll 网站上的任何浏览器都无法加载 Disqus
- jsf - 页面离开时也错误调用了 Bean 方法
- c# - 用 C# 中的正则表达式匹配 10 位或 12 位数字
- c# - C# 使用 For 循环进行列表排序
- c++ - 如何打印所有不同对的计数,它们的总和等于 k 比 O(n^2) c++ 更快?
- python - 产生语法错误
- php - 如何从数据库中的日期时间减去当前日期时间 - PHP
- android - 新添加的子数据不会填充新的卡片视图,它只会更新一张现有的卡片,所以应该在适配器中更改什么来填充新卡片
- reactjs - 无法从 React 获取 api 服务器数据