将CSS属性选择器与图标的样式化组件一起使用

时间:2018-10-01 19:36:40

标签: css styled-components next.js attribute-selector

我正在将NextJS用于React,SSR和样式化组件(带有哈希)。到目前为止,我设法用sass构建了主要的CSS结构。

nextjs.config.js

const withSass = require('@zeit/next-sass')
module.exports = withSass({
  cssModules: true,
  cssLoaderOptions: {
    importLoaders: 1,
    localIdentName: "[hash:base64:5]",
  }
})

问题是我不能使用attribute = value css选择器之类的方法; 对于图标,通常我定义如下的字体系列

[class^='icon-'] {
  font-family: 'fonticon'
}
.icon-foo {
  &:before {
    content: '\someunicode';
  }
}

当我运行build和.icon-foo类时,成功将其转换为某种哈希值并与CSS匹配。但是我不能使用属性/值选择器。

我知道无法转换这种选择器,但是我想问是否有任何解决方案,例如为cssLoaderOptions提供例外规则,

excludeClasses: /^.icon-/

所以我可以保留我的课程,因为它们仅用于图标。 谢谢。

ps:我知道我可以给<i>标签加上字体系列,但是我不愿意。

0 个答案:

没有答案
相关问题