如何将CSS模块与React使用并将样式保持在相同的(.jsx)文件中?
我想在.jsx文件中编写我的 CSS模块。类似于样式组件。这是我要实现的示例(请注意,这是一个文件):
// Cmp.jsx file
const styles = ???`
.wrapper {
display: flex;
.name {
color: blue;
}
}
`
export default function Cmp() {
return (
<div className={styles.wrapper}>
<div className={styles.name}>Bob</div>
</div>
)
}
是否有可以做到的库?
我可以从CSS模块的WebPack加载程序导入一些内部功能以代替???
?如果不是这样,请提示如果我想实现它应该查看的位置(实际上执行CSS模块导入的代码)将很有帮助。
请注意,样式的组件可以(AB)用于以类似的方式编写,但这无助于避免classNames/样式的碰撞。
I'd like to write my css modules in .jsx file. Similarly to styled-components. Here is an example of what I want to achieve (note that this is a single file):
// Cmp.jsx file
const styles = ???`
.wrapper {
display: flex;
.name {
color: blue;
}
}
`
export default function Cmp() {
return (
<div className={styles.wrapper}>
<div className={styles.name}>Bob</div>
</div>
)
}
Is there a library that allows to do it?
Can I import some internal function from webpack loader of css modules to use in place of ???
? If not then a hint on where I should look if I want to implement it (the code that actually does the import of css modules) would be helpful.
Note that styled components can be (ab)used to write in a similar manner but it won't help to avoid collisions of classnames/styles.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论