[英]Why create-react-app cant find my Sass variables
I create react app with create-react-app and setup the file structure like that:我使用 create-react-app 创建 react app 并设置如下文件结构:
src/
-index.js
-main.scss
pages/
-somepage.js
-somepage.scss
styles/
-_variables.scss
index.js索引.js
import './main.scss';
...
main.scss主文件
@import './styles/variables.scss';
_variables.scss _variables.scss
$primary: #000;
somepage.js somepage.js
import somepage.scss
somepage.scss somepage.scss
selector {
property: $primary; <-- sass can't find that
}
Any ideas please?请问有什么想法吗? Thank you.
谢谢你。
You need this...你需要这个...
npm install node-sass npm 安装 node-sass
https://www.npmjs.com/package/node-sass https://www.npmjs.com/package/node-sass
Can you try this ?你能试试这个吗?
@import './styles/variables';
@import './pages/somepage';
You could import all stylesheets in your main.scss and then all you need is import './main.scss';
您可以在main.scss 中导入所有样式表,然后您只需要
import './main.scss';
in index.js .在index.js 中。 You also don't have to to specify the suffix.
您也不必指定后缀。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.