【问题标题】:Make postcss work with jss of material ui使 postcss 与材料 ui 的 jss 一起工作
【发布时间】:2019-03-06 05:52:37
【问题描述】:

我在使用 Material UI 时遇到了这个问题:要构建在某些旧浏览器中运行的应用程序,需要添加 css 前缀,例如:

display:flex;

我想要的是打包后自动添加一些兼容性:

display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;

我的 CSS 是这样创建的:

import { withStyles } from '@material-ui/core';
const styles={
        root:{
              display:flex
          }
    }

export default withStyles(styles)(APP)

有人知道如何让它工作吗?

【问题讨论】:

    标签: javascript material-ui next.js


    【解决方案1】:

    您需要通过在项目根目录创建postcss.config.js 文件并定义导出来配置您的 postcss

    module.exports = {
      plugins: [
        require("postcss-easy-import")({ prefix: "_" }), // keep this first
        require('cssnano')({
          preset: 'default',
        }),
        require("autoprefixer")({
          browsers: [
            '>1%',
            'last 4 versions',
            'Firefox ESR',
            'not ie < 9',
          ]
        })
    ]};
    

    确保您的webpack 配置具有发帖规则:

    {
      test: /\.css$/,
      use: ["babel-loader", "raw-loader", "postcss-loader"]
    },
    {
      test: /\.s(a|c)ss$/,
      use: [
        "babel-loader", "raw-loader", "postcss-loader",
        {
          loader: "sass-loader",
          options: {
            includePaths: ["your/src/scss/style/file/location", "node_modules"]
              .map(d => require('path').join(__dirname, d))
              .map(g => require('glob').sync(g))
              .reduce((a, c) => a.concat(c), [])
          }
        }
      ]
    }
    

    我希望它对你有用。

    【讨论】:

    • 我看不到在此处应用 postcss-loader 的方法,因为它仅针对 css|scss 文件触发,但 OPs 文件具有 .js 扩展名。
    猜你喜欢
    • 2023-03-21
    • 2021-09-30
    • 2020-04-03
    • 1970-01-01
    • 1970-01-01
    • 2021-11-17
    • 2018-06-14
    • 2018-11-08
    • 2017-09-02
    相关资源
    最近更新 更多