【问题标题】:PostCSS CSSNext @media and color() not working with webpack 2PostCSS CSSNext @media 和 color() 不适用于 webpack 2
【发布时间】:2017-09-13 20:05:59
【问题描述】:

我正在将一个项目从 webpack 1 升级到 2,并且看到 postcss-cssnext 出现一些奇怪的行为,其中一些 css 下一个功能,最显着的是 color() 函数和我所有的 @media 查询不再起作用.

我的 webpack 配置与 webpack 2 看起来像这样。我在这里做错了什么?

{ 
  test: /\.css$/,
  use: [
    { 
      loader: 'style-loader' 
    },
    {
      loader: 'css-loader',
      options: {
        localIndentName: 'localIdentName=[name]__[local]___[hash:base64:5]',
        sourceMap: true,
        modules: true,
        importLoaders: 1
      }
    },
    {
      loader: 'postcss-loader',
      options: {
        plugins: [
          postcssImport({ path: './app/css/common' }),
          postcssCssnext({ browsers: ['> 1%', 'last 2 versions'] }),
          postcssReporter({ clearMessages: true })
        ]
      }
    }
  ]
}

【问题讨论】:

    标签: webpack-2 css-loader cssnext


    【解决方案1】:

    postcss-loader 可能是造成这种变化的原因(1.3.x)。 根据文档,您应该使用“插件”选项的功能。 或者在 postcss.config.js 文件中使用数组。

    module.exports = {
      module: {
        rules: [
          {
            test: /\.css/,
            use: [
              …
              {
                loader: 'postcss-loader',
                options: {
                  plugins: function () {
                    return [
                      postcssImport({ path: './app/css/common' }),
                      postcssCssnext({ browsers: ['> 1%', 'last 2 versions'] }),
                      postcssReporter({ clearMessages: true })
                    ];
                  }
                }
              }
            ]
          }
        ]
      }
    }
    

    或者通过 postcss.config.js

    module.exports = {
      plugins: [
        postcssImport({ path: './app/css/common' }),
        postcssCssnext({ browsers: ['> 1%', 'last 2 versions'] }),
        postcssReporter({ clearMessages: true })
      ]
    }
    

    (在 webpack 中)

    module.exports = {
      module: {
        rules: [
          {
            test: /\.css/,
            use: [
              …
              'postcss-loader',
            ]
          }
        ]
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2016-06-19
      • 2017-07-29
      • 2023-03-28
      • 2018-10-28
      • 2018-05-19
      • 2017-09-06
      • 2017-11-04
      • 2019-10-29
      • 1970-01-01
      相关资源
      最近更新 更多