1

I'm upgrading a project from webpack 1 to 2, and am seeing some strange behavior with postcss-cssnext where some css next features, most notably color() functions and all my @media queries just aren't working anymore.

My webpack config with webpack 2 looks like this. What am I doing wrong here?

{ 
  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 })
        ]
      }
    }
  ]
}
nicholas
  • 14,184
  • 22
  • 82
  • 138

1 Answers1

0

postcss-loader is probably responsible for this change (1.3.x). According to doc, you should use a function for "plugins" option. Or use an array but in a postcss.config.js file.

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 })
                ];
              }
            }
          }
        ]
      }
    ]
  }
}

Or via postcss.config.js

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

(and in webpack)

module.exports = {
  module: {
    rules: [
      {
        test: /\.css/,
        use: [
          …
          'postcss-loader',
        ]
      }
    ]
  }
}
MoOx
  • 8,423
  • 5
  • 40
  • 39