简体   繁体   English

SASS:未渲染index.js中导入的scss(使用create-react-app)

[英]SASS: imported scss in index.js not rendering (using create-react-app)

I'm working on a create-react-app project, which I hooked SASS to, using these instructions: https://github.com/facebook/create-react-app 我正在使用一个create-react-app项目,使用以下说明将SASS连接到该项目: https : //github.com/facebook/create-react-app

Then, in my source, I created a style folder with a partials folder and an index.scss. 然后,在我的源代码中,我创建了一个样式文件夹,其中包含一个partials文件夹和一个index.scss。 Inside the partials folder, I have a firstComponent.scss file. 在partials文件夹中,我有一个firstComponent.scss文件。 I imported the scss from the firstComponent file into my index.scss. 我将scss从firstComponent文件导入到index.scss中。 The styles are being successfully imported into my index.css file. 样式已成功导入到我的index.css文件中。 However, they are not being rendered on the browser. 但是,它们不会在浏览器上呈现。 Why is this? 为什么是这样?

here is my index.js 这是我的index.js

import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
import registerServiceWorker from './registerServiceWorker';
import './style/index.scss';

ReactDOM.render(<App />, document.getElementById('root'));
registerServiceWorker();

here is my index.scss 这是我的index.scss

@import './partials/_firstComponent';  

body {
  margin: 0;
  padding: 0;
  font-family: sans-serif;
}

here is my firstComponent.scss 这是我的firstComponent.scss

.firstComponent {
    background-color: 'red'; 
}

here is my index.css 这是我的index.css

.firstComponent {
  background-color: 'red'; }

body {
  margin: 0;
  padding: 0;
  font-family: sans-serif; }

You will need this line instead 您将需要此行

require('./style/index.scss'); require('./ style / index.scss');

NOT

import './style/index.scss'; 导入'./style/index.scss';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 .scss 文件作为模块而不用 .modules create-react-app 命名它们 - Using .scss files as modules without naming them with .modules create-react-app 如何使用 Create-React-App 为 sass-resources-loader 设置 Webpack? - How to setup Webpack using Create-React-App for sass-resources-loader? 为什么 create-react-app 找不到我的 Sass 变量 - Why create-react-app cant find my Sass variables reactjs create-react-app bootstrap4卡无法正确渲染 - reactjs create-react-app bootstrap4 card not rendering correctly index.js 尝试导入错误:“./App”不包含默认导出(导入为“App”) - index.js attempted import error: './App' does not contain a default export (imported as 'App') 将自定义样式表导入create-react-app的app.scss - Import custom stylesheets into create-react-app's app.scss 从我使用 create-react-app 的 react 项目中删除 node-sass - Remove node-sass from my react project which uses create-react-app 主题 Sass,React 应用程序上的 scss 主题混合 - theming Sass, scss themes mixin on React app 带有 Node-SASS 和 CSS 模块的 Create-React-App v2 在本地工作但在 Heroku 中崩溃 - Create-React-App v2 with Node-SASS and CSS Modules works locally but crashes in Heroku 如何使用导入全局 sass 变量与 create-react-app(弹出) - How to use import global sass variables with create-react-app (ejected)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM