[英]The problem of css-loader modularization in react
After the css-loader is modularized, the class names are automatically renamed. css-loader模块化后,自动重命名class名称。 After the modularization is enabled, the pseudo-elements can no longer be used.
启用模块化后,伪元素就不能再使用了。 What should I do?
我应该怎么办? For example:
.title
is renamed to .abc
, the previously defined .title:after
cannot be used例如:
.title
重命名为.abc
,之前定义的.title:after
不能使用
After properly configured css-loader
for enabling CSS modules you must not use React className
with a string.在正确配置
css-loader
以启用 CSS 模块后,您不能将 React className
与字符串一起使用。 So don't use :所以不要使用:
<h1 className="title">
Instead you must import the CSS and use rules inside.相反,您必须导入 CSS 并在其中使用规则。
import styles from "./style.css";
// ...
<h1 className={styles.title}>
In this way the generated class name will always match the hashed result.这样,生成的 class 名称将始终与散列结果匹配。
See the CSS Modules reference for more info.有关详细信息,请参阅CSS 模块参考。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.