简体   繁体   English

你如何在 create-react-app 中使用 sass 和 typescript?

[英]how do you use sass in create-react-app with typescript?

I created a fresh project using create-react-app and typescript and added a sass file in my project (in create-react-app docs it says that it supports sass file out of the box) but I'm getting this error for my sass file:我使用 create-react-app 和 typescript 创建了一个新项目,并在我的项目中添加了一个 sass 文件(在 create-react-app 文档中它说它支持 Z1F8DC276F8040001419C64E9D18F09 的错误文件) sass 文件:

Failed to compile.

./src/homepage.style.sass (./node_modules/css-loader/dist/cjs.js??ref--6-oneOf-5-1!./node_modules/postcss-loader/src??postcss!./node_modules/resolve-url-loader??ref--6-oneOf-5-3!./node_modules/sass-loader/dist/cjs.js??ref--6-oneOf-5-4!./src/homepage.style.sass)
SassError: Invalid CSS after ".homepage {": expected "}", was "{"
        on line 1 of /home/taghi/wt-projects/react-ecommerce/src/homepage.style.sass
>> .homepage { {

   -----------^

and here is my Sass file content:这是我的 Sass 文件内容:

.homepage {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px 80px;
}

.directory-menu {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
}

.menu-item {
  min-width: 30%;
  height: 240px;
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid black;
  margin: 0 7.5px 15px;

  &:first-child {
    margin-right: 7.5px;
  }

  &:last-child {
    margin-left: 7.5px;
  }

  .content {
    height: 90px;
    padding: 0 25px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border: 1px solid black;

    .title {
      font-weight: bold;
      margin-bottom: 6px;
      font-size: 22px;
      color: #4a4a4a;
    }

    .subtitle {
      font-weight: lighter;
      font-size: 16px;
    }
  }
}

Any help would be appreciated任何帮助,将不胜感激

Sass does not need curly brackets and semicolons. Sass 不需要大括号和分号。 So it should look like this,所以它应该看起来像这样,

.homepage display: flex flex-direction: column align-items: center padding: 20px 80px

You can just remove the curly brackets and semicolons in the current CSS code or json Formatter to convert CSS to SASS.您只需删除当前 CSS 代码或json 格式化程序中的花括号和分号即可将 Z2C56C360580420D293172F42D85DFBED015B61AC21580ACBEDZ 转换为 Z2C56C360580420D293172F42D85DFBED015B61AC21580ACBA6

It doesn't need "{}",only use indentation不需要"{}",只需要缩进

.homepage 
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px 80px;

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM