0

当我使用postcss-loaderpostcss-cssnext插件时,css-class在第二个嵌套的前面可以起作用,在第三个嵌套将不起作用

style.css

    .root {
        background-color: #ccc;

        & .header {
            height: 60px;
            background-color: #dcdcdc;
        }

        & .content {
            border: 1px solid red;

            & .test { /* doesn't work */
                background-color: #00f;
                height: 200px;
            }
        }
    }

app.tsx

    <div className={style.root}>
        <div className={style.header}>
          Hello test
        </div>
        <div className={style.content}>
            <div className={style.test}>

            </div>
        </div>
    </div>

postcss-loader config

    {
      loader: 'postcss-loader',
      options: {
        sourceMap: true,
        sourceComments: true,
        plugins: [
          require('postcss-import')({
            root: path.join(__dirname, './'),
            path: [ path.join(__dirname, './src/toolkit') ]
          }),
          require('postcss-at-rules-variables')({
            variables: makeAtRulesVariables(injectedCssVariables)
          }),
          require('postcss-modules-values'),
          require('postcss-mixins')(),
          require('postcss-each')(),
          require('postcss-cssnext')({
            features: {
              customProperties: {
                variables: injectedCssVariables
              }
            }
          }),
          require('postcss-reporter')({
            clearMessages: true
          })
        ]
      }
    }
4

1 回答 1

0

您能否在您的样式表和配置文件中进行这些更改。

样式.css

.root {
    background-color: #ccc;

    .header {
        height: 60px;
        background-color: #dcdcdc;
    }

    .content {
        border: 1px solid red;

        .test { /* doesn't work */
            background-color: #00f;
            height: 200px;
        }
    }
}

postcss-loader 配置

{
  loader: 'postcss-loader',
  options: {
    sourceMap: true,
    sourceComments: true,
    plugins: [
      require('postcss-import')({
        root: path.join(__dirname, './'),
        path: [ path.join(__dirname, './src/toolkit') ]
      }),
      require('postcss-at-rules-variables')({
        variables: makeAtRulesVariables(injectedCssVariables)
      }),
      require('postcss-mixins')(),
      require('postcss-each')(),
      require('postcss-cssnext')({
        features: {
          customProperties: {
            variables: injectedCssVariables
          }
        }
      }),
      require('postcss-modules-values'),
      require('postcss-reporter')({
        clearMessages: true
      })
    ]
  }
}
于 2017-08-23T06:16:47.833 回答