【问题标题】:Can I use class with variable parameter in PostCSS?我可以在 PostCSS 中使用带有可变参数的类吗?
【发布时间】:2017-11-09 18:55:51
【问题描述】:

我可以在PostCss 中使用带有可变参数的类吗?

类似这样的:

.my-class(varWidth) { width: varWidth }

比在 React 组件中使用这个类:

import {myClass} import './MyComponent.scss'

...

<div className={myClass(100px)}></div>

【问题讨论】:

    标签: css reactjs postcss


    【解决方案1】:

    您可能需要为此使用 PostCSS 加载器(用于 webpack 的加载器以使用 PostCSS 处理 CSS)。 通过以下方式安装 PostCSS 加载器:

    npm i -D postcss-loader
    

    配置 postcss.config.js

    module.exports = {
    parser: 'sugarss',
    plugins: {
    'postcss-import': {},
    'postcss-cssnext': {},
    'cssnano': {}
     }
    }
    

    您可以在此处阅读有关常见 PostCSS 配置的更多信息。https://github.com/michael-ciniawsky/postcss-load-config

    【讨论】:

    • 谢谢。实际上我正常安装 PostCSS 并且它工作正常。我不知道这个库是否有决定我问题的工具(目前我没有找到这个能力)。特别是使用类作为带有可变参数的函数。
    猜你喜欢
    • 2014-09-01
    • 2014-06-07
    • 1970-01-01
    • 2010-12-09
    • 1970-01-01
    • 2021-12-26
    • 2011-04-06
    • 1970-01-01
    • 2023-03-24
    相关资源
    最近更新 更多